Unknown keys with find_or_create on associations #2554

Sephi-Chan opened this Issue Aug 17, 2011 · 3 comments


None yet

3 participants



I issue a bug with find_or_create with Rails 3.0.9 on Ruby 1.8.7 when used on an association.
There is no problem with find_or_initialize.

Here is the code that shows all behaviors (regardless I use strings or symbols) :

game   = Game.first
key    = "quest.1.title"
locale = "fr"

# With multiple arguments and a hash.
game.texts.find_or_create_by_locale_and_key(locale, key, :value => "")
# ArgumentError: Unknown key(s): value

# With just a hash.
game.texts.find_or_create_by_locale_and_key(:locale => locale, :key => key, :value => "")
# ArgumentError: Unknown key(s): value, key, locale

It's not good according to the tests.
How can I help fixing that ? I noticed there was a test (test_find_or_create_with_one_attribute_followed_by_hash) for one argument and a hash but not for more. Should I create it ?

Ruby on Rails member

Hey can you please confirm this again. Is this still a issue with the latest version??

Ruby on Rails member

Closing this for now. Please let me know if problem still exists.

@arunagw arunagw closed this Feb 5, 2012

This is still an issue in 3.0.11. The problem stems from lines 424-427 of ActiveRecord::Associations::AssociationCollection where it tries to intercept find_or_create_by dynamic finders rather than letting AR::Base handle them normally. Note that find_or_initialize_by finders work correctly as they fall through to the block at line 440 and are sent to AR::Base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment