This project is archived and is in readonly mode.
ActiveRecord::Relation#scope_for_create wrongly merges other table's conditions having same attribute name
Reported by Akira Matsuda | July 28th, 2010 @ 09:41 PM | in 3.0.2
When a relation being merged with another relation based on other model, its scope_for_create are wrongly overwritten.
For example, a Pirate's name are overwritten by his Ship's name
in the following code.
> (Pirate.where(:name => 'Monkey D. Luffy').joins(:ship) & Ship.where(:name => 'Going Merry')).scope_for_create
#=> {:name=>"Going Merry"}
Attached a patch for fixing this.
This patch depends on another patch for #5184 , so
please apply both two patches, or the tests won't pass.
Comments and changes to this ticket
-
Akira Matsuda August 22nd, 2010 @ 10:14 PM
Updated the patch so that it applies to the current Edge.
Again, this patch depends on the patch for #5184 -
José Valim August 23rd, 2010 @ 01:25 AM
- Milestone cleared.
- Assigned user set to Aaron Patterson
- Importance changed from to Low
-
Aaron Patterson August 23rd, 2010 @ 01:40 AM
- State changed from new to incomplete
Hey Akira, I tried applying this patch, but the test you provide fails. Can you check the patch?
$ ruby -w -I"lib:test:test/connections/native_sqlite3" test/cases/method_scoping_test.rb -n test_scoped_create_with_join_and_merge /Users/apatterson/git/arel/lib/arel/algebra/attributes/attribute.rb:70: warning: method redefined; discarding old root Using native SQLite3 Loaded suite test/cases/method_scoping_test Started F Finished in 0.023906 seconds. 1) Failure: test_scoped_create_with_join_and_merge(MethodScopingTest) [test/cases/method_scoping_test.rb:231:in `test_scoped_create_with_join_and_merge' /Users/apatterson/git/rails/activerecord/lib/active_record/base.rb:1123:in `with_scope' /Users/apatterson/git/rails/activerecord/lib/active_record/relation.rb:360:in `send' /Users/apatterson/git/rails/activerecord/lib/active_record/relation.rb:360:in `method_missing' /Users/apatterson/git/rails/activerecord/lib/active_record/relation.rb:120:in `scoping' /Users/apatterson/git/rails/activerecord/lib/active_record/relation.rb:360:in `method_missing' test/cases/method_scoping_test.rb:230:in `test_scoped_create_with_join_and_merge' /Users/apatterson/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `__send__' /Users/apatterson/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `run' /Users/apatterson/git/rails/activesupport/lib/active_support/callbacks.rb:418:in `_run_setup_callbacks' /Users/apatterson/git/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run']: <{:body=>"but Who's Buying?"}> expected but was <{}>. 1 tests, 1 assertions, 1 failures, 0 errors
-
Repository October 30th, 2010 @ 09:26 PM
- State changed from incomplete to resolved
(from [296467fcc40bb3c6a4f42dedc267eb4f313843a9]) only returning where values for the corresponding relation, also filtering where value hash based on table name [#5234 state:resolved] [#5184 state:resolved] http://github.com/rails/rails/commit/296467fcc40bb3c6a4f42dedc267eb...
-
Repository October 30th, 2010 @ 09:37 PM
(from [29b3af539b1a61141a42adb04b78d86433bdd21e]) only returning where values for the corresponding relation, also filtering where value hash based on table name [#5234 state:resolved] [#5184 state:resolved] http://github.com/rails/rails/commit/29b3af539b1a61141a42adb04b78d8...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5184 ActiveRecord::Relation#merge merges other table's conditions having same attribute name (from [296467fcc40bb3c6a4f42dedc267eb4f313843a9]) only re...
- 5234 ActiveRecord::Relation#scope_for_create wrongly merges other table's conditions having same attribute name (from [296467fcc40bb3c6a4f42dedc267eb4f313843a9]) only re...
- 5234 ActiveRecord::Relation#scope_for_create wrongly merges other table's conditions having same attribute name (from [29b3af539b1a61141a42adb04b78d86433bdd21e]) only re...
- 5184 ActiveRecord::Relation#merge merges other table's conditions having same attribute name (from [29b3af539b1a61141a42adb04b78d86433bdd21e]) only re...