Skip to content

Commit

Permalink
Fix Association between Nodes and EssenceNodes (AlchemyCMS#1826)
Browse files Browse the repository at this point in the history
There was a typo here resulting in Nodes being associated to themselves
in an impossible way.
  • Loading branch information
mamhoff authored May 13, 2020
1 parent 0eec65a commit 729cd21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/alchemy/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Node < BaseRecord

has_one :site, through: :language

has_many :essence_nodes, class_name: "Alchemy::Node", inverse_of: :node
has_many :essence_nodes, class_name: "Alchemy::EssenceNode", foreign_key: :node_id, inverse_of: :ingredient_association

validates :name, presence: true, if: -> { page.nil? }
validates :url, format: { with: VALID_URL_REGEX }, unless: -> { url.nil? }
Expand Down
2 changes: 2 additions & 0 deletions spec/models/alchemy/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module Alchemy
describe Node do
it { is_expected.to have_many(:essence_nodes) }

it "is only valid with language and name given" do
expect(Node.new).to be_invalid
expect(build(:alchemy_node)).to be_valid
Expand Down

0 comments on commit 729cd21

Please sign in to comment.