Subject: Using finders to apply conditions on the associations?
Say I have a model Post, which can have many Comments. i.e., Post has the association
$has_many = array("comments"),
and each Comment has the association
$belongs_to = array("post").
Now say I want to fetch all posts with comments written after a certain date. How do I specify this condition on the association? Something to the effect of the following WHERE clause:
WHERE comments.created_at > 'some date'
I know one solution is to fetch by comments (Comment::all()), and include the post associations via eager loading, but can I do this by querying the posts instead (Post::all())?
Subject: Using finders to apply conditions on the associations?
Say I have a model Post, which can have many Comments. i.e., Post has the association
$has_many = array("comments"),
and each Comment has the association
$belongs_to = array("post").
Now say I want to fetch all posts with comments written after a certain date. How do I specify this condition on the association? Something to the effect of the following WHERE clause:
WHERE comments.created_at > 'some date'
I know one solution is to fetch by comments (Comment::all()), and include the post associations via eager loading, but can I do this by querying the posts instead (Post::all())?