This is related to #7661 and I am opening this ticket to demonstrate the problem,
class Article < ActiveRecord::Base
attr_accessible :content, :title
has_many :tags, :through => :article_tags
before_validation :add_to_default_tag, :on => :create
self.tags << Tag.find_or_create_by_title("default")
class Tag < ActiveRecord::Base
has_many :articles, :through => :article_tags
class ArticleTag < ActiveRecord::Base
attr_accessible :article_id, :name, :tag_id
article = Article.new(:title => "hemant", :content => "kumar")
For the lazy, there is a repo https://github.com/gnufied/try_through which reproduces the same problem. I can perhaps add some ActiveRecord tests as well quickly.
@gnufied if you can add a failing test to AR, I'd really appreciate it. Otherwise, I need to translate your example to a failing AR test (I can do that, it will just take me longer).
Thanks for filing this issue!
here it goes - https://gist.github.com/4497186
does that work, @tenderlove
I have confirmed this behaviour too and concluded that it is related to #7661. I reverted the changes introduced in #7661 using the following however it's not ideal.
I would encourage whoever cherry picked #7661 into 3-2-stable to remove it, if necessary, introduce it in 4.0 with documentation about the changed behaviour when saving these associations.
Because #7661 was reverted this is fixed. But I believe there should be some tests for existing behaviour.
@gnufied I agree. I will make add a test before closing this issue.
@tenderlove ... #7661 was reverted on 3.2 but is still on the master branch. Is rails 4 supposed to go out with the change?
This issue has been automatically marked as stale because it has not been commented on for at least
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 4-1-stable, 4-0-stable branches or on master,
please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
This issue has been automatically closed because of inactivity.