I have 2 models
class Article < ActiveRecord::Base
has_many :images
end
and
class Image < ActiveRecord::Base
belongs_to :article
end
how can I get all the articles without images
尝试这个:
Article.where('id NOT IN (?)', Image.all.pluck(:article_id).uniq)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.