I’m not quite sure how to get at this data using Actrive record… I’m trying to get all the appointments made for a particular project. I’m using four models, Projects, Tasks, Resources and Appointments.
The SQL gets me what I’m looking for but how do I do it using Active Record?
Select a.* from appointments a
join resources r on r.id = a.resource_id
join tasks t on t.id = r.task_id
join projects p on p.id = t.project_id
Where project_id = 1;
I can get all the Resources for a project using this but can not get the appointments. I could loop through the resources getting all the appointments and tracking them, but that doesn’t seem like the right way to do it. I could also use find_by_sql, but again, that does’t seem right.
I'm not quite sure how to get at this data using Actrive record.. I'm trying to get all the appointments made for a particular project. I'm using four models, Projects, Tasks, Resources and Appointments.
The SQL gets me what I'm looking for but how do I do it using Active Record?
Select a.* from appointments a
join resources r on r.id = a.resource_id
join tasks t on t.id = r.task_id
join projects p on p.id = t.project_id
Where project_id = 1;
Why is project joined in, if project_id comes from tasks?
And why is resources joined in? for its data? It does not participate in the links, right?
I can get all the Resources for a project using this but can not get the appointments. I could loop through the resources getting all the appointmen ts and tracking them, but that doesn't seem like the right way to do it. I could also use find_by_sql, but again, that does't seem right.