ruby - Return a query with nested results with Rails ActiveRecord -


I am trying to get a list of active tasks for a workflow tool, in this way with structured data

  • has_many projects
    • has_many subprojects
      • has_many tasks
        • has_many TimeLogs
        • I am trying to display this complete structure as the main page, but at only a few levels show an active working parent structures.

          So far I've tried:

          • On any of the four tables included, which produce fake rows
          • A statement somewhere , Which only gives to relevant users, but when I try to reach my children, WHERE has not retained the clause

The nested level of problem due to

This can be quite complex. As I understand, you want to leave the user. Projects | Subproducts, which do not have any active functions, are not an ordinary SQL that will get you:

  users.each do | User | User.active_projects.each do | Project | Instead, I first query for functions, i.e.  @tasks = Task.includes (: subproject => [: project =>: user]]  
). Where ("not in status ('full')") . After that you have incomplete tasks and now you only need to re-order the desired data, I mean:

  @tasks = @tasks .group_by {| T | T.subproject.project.user} .reduce ({}) do it. Yoga, (user, work). Yoga [user] || = {} Tasks.each do | Work | Sum [user] [task.subproject.project] || = {} Sum [user] [task.subproject.project] [task.subproject] || = [] Amount [user] [task.subproject.project] [work .subproject] & lt; & Lt; End of task end  

I have not tested this, but this is the idea.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -