Skip to content

Commit

Permalink
Add missing inverse_of's
Browse files Browse the repository at this point in the history
Without these inverse_of's Rails loads the records even if they have
been eager loaded.
  • Loading branch information
tvdeyen committed Nov 15, 2019
1 parent 1f1955d commit ac18eca
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Content < BaseRecord
# Concerns
include Alchemy::Content::Factory

belongs_to :essence, polymorphic: true, dependent: :destroy
belongs_to :essence, polymorphic: true, dependent: :destroy, inverse_of: :content
belongs_to :element, touch: true, inverse_of: :contents
has_one :page, through: :element

Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Element < BaseRecord

# Content positions are scoped by their essence_type, so positions can be the same for different contents.
# In order to get contents in creation order we also order them by id.
has_many :contents, -> { order(:position, :id) }, dependent: :destroy
has_many :contents, -> { order(:position, :id) }, dependent: :destroy, inverse_of: :element

has_many :all_nested_elements,
-> { order(:position) },
Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/essence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def acts_as_essence(options = {})
stampable stamper_class_name: Alchemy.user_class_name
validate :validate_ingredient, on: :update, if: -> { validations.any? }
has_one :content, as: :essence, class_name: "Alchemy::Content"
has_one :content, as: :essence, class_name: "Alchemy::Content", inverse_of: :essence
has_one :element, through: :content, class_name: "Alchemy::Element"
has_one :page, through: :element, class_name: "Alchemy::Page"
Expand Down

0 comments on commit ac18eca

Please sign in to comment.