ruby on rails - ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection with these associations -


i have these models:

familytree

# == schema information # # table name: family_trees # #  id         :integer          not null, primary key #  name       :string(255) #  user_id    :integer  class familytree < activerecord::base   attr_accessible :name   belongs_to :user   has_many :memberships, dependent: :destroy   has_many :active_members, through: :memberships, source: :user, dependent: :destroy   has_many :passive_members, through: :memberships, source: :member, dependent: :destroy   has_many :nodes, dependent: :destroy   has_many :members, through: :memberships, dependent: :destroy end 

membership

# == schema information # # table name: memberships # #  id                      :integer          not null, primary key #  family_tree_id          :integer #  user_id                 :integer #  member_id               :integer  class membership < activerecord::base   belongs_to :family_tree   belongs_to :user   belongs_to :member     end 

member

# == schema information # # table name: members # #  id             :integer          not null, primary key #  email          :string(255) #  family_tree_id :integer #  class member < activerecord::base     attr_accessor :relation       has_many :memberships, dependent: :destroy     belongs_to :family_tree          end 

node

# == schema information # # table name: nodes # #  id                       :integer          not null, primary key #  name                     :string(255) #  family_tree_id           :integer #  user_id                  :integer #  media_id                 :integer  class node < activerecord::base   belongs_to :family_tree   belongs_to :user   belongs_to :media, polymorphic: true, dependent: :destroy   has_many :comments, dependent: :destroy   has_many :memberships, through: :family_tree, dependent: :destroy     end 

when try delete node, error:

[109] pry(main)> n = node.last   node load (0.8ms)  select  "nodes".* "nodes"   order "nodes"."id" desc limit 1 => #<node id: 102, name: "10pp burpees", family_tree_id: 57, user_id: 57, media_id: 246> [110] pry(main)> n.destroy    (0.1ms)  begin   actsastaggableon::tagging load (1.4ms)  select "taggings".* "taggings"  "taggings"."taggable_id" = $1 , "taggings"."taggable_type" = $2  [["taggable_id", 102], ["taggable_type", "node"]]   actsastaggableon::tagging load (0.5ms)  select "taggings".* "taggings" inner join "tags" on "tags"."id" = "taggings"."tag_id" "taggings"."taggable_id" = $1 , "taggings"."taggable_type" = $2 , "taggings"."context" = 'user_tags'  [["taggable_id", 102], ["taggable_type", "node"]]   actsasvotable::vote load (0.5ms)  select "votes".* "votes"  "votes"."votable_id" = $1 , "votes"."votable_type" = $2  [["votable_id", 102], ["votable_type", "node"]]   sql (0.3ms)  delete "votes" "votes"."id" = $1  [["id", 51]]   video load (0.4ms)  select  "videos".* "videos"  "videos"."id" = $1 limit 1  [["id", 246]]   sql (0.2ms)  delete "videos" "videos"."id" = $1  [["id", 246]]   comment load (0.3ms)  select "comments".* "comments"  "comments"."node_id" = $1  [["node_id", 102]]   membership load (1.1ms)  select "memberships".* "memberships" inner join "family_trees" on "memberships"."family_tree_id" = "family_trees"."id" "family_trees"."id" = $1  [["id", 57]]    (0.3ms)  rollback activerecord::hasmanythroughcantassociatethroughhasoneormanyreflection: cannot modify association 'node#memberships' because source reflection class 'membership' associated 'familytree' via :has_many. /.rvm/gems/ruby-2.1.6@myapp/gems/activerecord-4.1.12/lib/active_record/associations/through_association.rb:86:in `ensure_mutable' 

i error associations, think close , can't figure out causing particular issue.

ideas?

so issue turns out have been line in node.rb:

has_many :memberships, through: :family_tree, dependent: :destroy 

i realized didn't need it, axed it.

that solved issue , got rid of error.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -