Ruby on rails Rails 4:如何从关联中合并作用域?
我有一个简单的问题 我有几个相关的模型:Ruby on rails Rails 4:如何从关联中合并作用域?,ruby-on-rails,rails-activerecord,Ruby On Rails,Rails Activerecord,我有一个简单的问题 我有几个相关的模型: class Video < ActiveRecord::Base include ContentSharable scope :published, -> { where(visible: true).where 'published_at <= ?', Time.zone.now } end class ContentShare < ActiveRecord::Base belongs_to :sharable, po
class Video < ActiveRecord::Base
include ContentSharable
scope :published, -> { where(visible: true).where 'published_at <= ?', Time.zone.now }
end
class ContentShare < ActiveRecord::Base
belongs_to :sharable, polymorphic: true
scope :for_feed, -> { where.not(image: nil) }
end
class-Video 作用域:published,->{where(可见:true)。where'published_at您可以使用scoped
方法:
relation=ContentShare.for\u feed.scoped.merge(Video.published)
有关更多详细信息,请参阅文档:
我试过了,但ContentShare是一个多病态的协会,我有“视频”、画廊和其他课程。。。