Strong association error with has_many: via union

//////// UPDATE

This is the output from the dev log when I submit the form as an update

LogoCategory Load (0.3ms) SELECT logo_categories

. The FROM * logo_categories

an INNER a JOIN logos

ON logo_categories

. id

= logos

. logo_category_id

INNER JOIN logos_posts

ON logos

. id

= logos_posts

. logo_id

WHERE logos_posts

. post_id

= 61

//////////////

If you had an app installation like below, someone might be wondering why they get this error ... I can't find any information anywhere.

ActiveRecord :: HasManyThroughNestedAssociationsAreReadonly in PostsController update #

The association 'Post # logo_categories' cannot be changed because it is across more than one association.

post.rb

has_and_belongs_to_many :logos
has_many :logo_categories, :through => :logos  

      

logo.rb

  belongs_to :logo_category
  has_and_belongs_to_many :posts

      

logo_category.rb

has_many :logos
has_and_belongs_to_many :posts

      

and my tables ...

posts (id), logos (id), logos_posts (id, logo_id, logo_category_id), logo_categories (id)

I get an error when I try to save a _form post model ONLY while editing a post, and I check or uncheck the box marked logo_category.

Any ideas are appreciated! Thanks to

+3


source to share


1 answer


Try:

post.rb

has_and_belongs_to_many :logos

      

logo.rb

has_and_belongs_to_many :posts

      

EDITED :



Your migration 'logo_categories' looks like this:

  create_table :logo_categories do |t|
    t.references :logo
    t.references :post
    t.timestamps
  end

      

Take a look at the link, it will help you use the HABTM:

http://asciicasts.com/episodes/17-habtm-checkboxes

http://ramblings.gibberishcode.net/archives/rails-has-and-belongs-to-many-habtm-demystified/17

+1


source







All Articles