ruby on rails 3 - Active record query relationship -
i have models called project
, gold_task
, submissions
.
relationship goes this:
project has_many gold_tasks
gold_tasks has_many submissions
how can submissions of gold_task through project id.
i tried in below way
p.gold_tasks.joins(:submissions)
here i'm getting gold_tasks need submissions.
thanks in advance.
i believe question right here "how can submissions of gold_task through project id?"
if have set rails associations correctly, should able this:
@project = project.find(1) @gold_tasks = @project.gold_tasks
rails automatically rows in gold_tasks table rows project id of 1 , return array of finds. furthermore, building objects easy well. let's assume have project row again:
@project = project.find(1) @gold_task = @project.gold_task.build(hash)
this build new gold_task parameter hash , assign @project id it.
check out guide: http://guides.rubyonrails.org/association_basics.html
Comments
Post a Comment