module RailsConnector class Channel < CmsBaseModel self.primary_key = "channel_name" def self.table_name "#{table_name_prefix}" "channels" end has_many :news, class_name: "RailsConnector::News", foreign_key: "channel_name" has_many :active_news, -> { where(["valid_from <= :now AND valid_until >= :now", { now: Time.now.to_s(:number) }]) }, class_name: "RailsConnector::News", foreign_key: "channel_name" has_many :objects, through: :news scope :with_prefix, ->(prefix) { where(["channel_name LIKE ?", "#{prefix}%"]) } end end