Created
December 2, 2012 20:21
-
-
Save pootsbook/4190871 to your computer and use it in GitHub Desktop.
Ignore records with no attached records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$options['joins'] = array( | |
array('table' => 'images_news_articles', | |
'alias' => 'ImagesNewsArticle', | |
'type' => 'left outer', | |
'conditions' => array( | |
'NewsArticle.id = ImagesNewsArticle.news_article_id' | |
) | |
), | |
array('table' => 'images', | |
'alias' => 'Image', | |
'type' => 'left outer', | |
'conditions' => array( | |
'ImagesNewsArticle.image_id = Image.id' | |
) | |
) | |
); | |
$options['conditions'] = array( | |
'Image.id IS NOT NULL' | |
); | |
$news_articles_with_images = $NewsArticle->find('all', $options); |
scope :imaged, lambda { includes(:images).where("images.id IS NOT NULL") }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Rails: