Not doing so has a few gotchas when working with relations, particularly with records which are not stored in the database. I'm excluding the related content file because it's got a very peculiar relationship with itself: the `has_one :opposite_related_content` has no inverse; the relation itself is its inverse. It's a false positive since the inverse condition is true: ``` content.opposite_related_content.opposite_related_content.object_id == content.object_id ```
25 lines
619 B
Ruby
25 lines
619 B
Ruby
class Widget::Card < ApplicationRecord
|
|
include Imageable
|
|
belongs_to :page,
|
|
class_name: "SiteCustomization::Page",
|
|
foreign_key: "site_customization_page_id",
|
|
inverse_of: :cards
|
|
|
|
# table_name must be set before calls to 'translates'
|
|
self.table_name = "widget_cards"
|
|
|
|
translates :label, touch: true
|
|
translates :title, touch: true
|
|
translates :description, touch: true
|
|
translates :link_text, touch: true
|
|
include Globalizable
|
|
|
|
def self.header
|
|
where(header: true)
|
|
end
|
|
|
|
def self.body
|
|
where(header: false, site_customization_page_id: nil).order(:created_at)
|
|
end
|
|
end
|