This project is archived and is in readonly mode.
has_many with :primary_key option bug
-
Frederick Cheung
That's odd as foo.id always gets you the value of the primary key (whether it's called id or not) - I'm not sure the change in the patch accomplishes anything.
-
Roman Shterenzon
Perhaps I fixed it in the wrong place, but it surely fixes the bug that I found while working on my application. Since the "primary_key" option is a part of the reflection object, I'm not sure that it's known to the association owner, and the only thing that can change "id" is the 'set_primary_key' for the owner class (but it's something different). Maybe I got it wrong.
-
Frederick Cheung
D'oh - read a little too quickly !
-
Repository
- State changed from new to resolved
(from [21efba464afa2ae6e5dfd938ac8a3ce446faf7e7]) Fix HasManyAssociation#create ignoring the :primary_key option [#1633 has_many with :primary_key option bug state:resolved]
Signed-off-by: Frederick Cheung frederick.cheung@gmail.com http://github.com/rails/rails/co...
-
Roman Shterenzon
Is it possible to merge this to 2-2-stable branch?
-
Repository
(from [7276128fb47d5997437eb5452b4e9a82ee54f4a8]) Fix HasManyAssociation#create ignoring the :primary_key option [#1633 has_many with :primary_key option bug state:resolved]
Signed-off-by: Frederick Cheung frederick.cheung@gmail.com http://github.com/rails/rails/co...
-
Brian Johnson
This is not completely resolved, please see http://github.com/johnsbrn/rails...
-
Roman Shterenzon
Brian, I've seen your commit, but I didn't quite understand what is missing in the current fix. Can you elaborate? Or, perhaps, define a failing test.
-
Brian Johnson
There is still an issue in has_one in associations.rb and new_record in has_one_association.rb. There are some tests included in the commit, but just from looking at the code you can see that it's still using id instead of the primary_key option if it exists.
-
Brian Johnson
I also made an update to make one of the changes consistent with the existing fix from this ticket.
-
Brian Johnson
Sorry, just one more thing, this started as ticket 1756 http://rails.lighthouseapp.com/p...
-
Roman Shterenzon
So, if I get it right, it has nothing to do with 'has_many' association? If this is indeed the case, then this bug can be closed.
-
Brian Johnson
Oops, my bad. Yes, this is for a bug with has_one. I guess I had has_one on my mind so I saw has_one instead of has_many in the title. There is a similar bug in has_one that is addressed by my patch which is in ticket 1756.
-
tribalvibes
- Tag changed from 2.2, has_many, primary_key to 2.3.10, 2.3.8, 2.3.x, has_many, primary_key
This is still a bug in 2.3.8. Seems the fixes have not been integrated?
class Service < ActiveRecord::Base # attributes: pk id, proxy_id, etc. has_many :clients, primary_key: :proxy_id, foreign_key: :proxy_id, before_add: :client_add def client_add( b ) #!!! here b.proxy_id is not set correctly end end p = Service.first.clients.create # p.proxy_id is set to Service.first.id (i.e. the class pk) rather than proxy_id # which is the designated pk for the association -
Andrea Campi
- Tag changed from 2.3.10, 2.3.8, 2.3.x, has_many, primary_key to 2-3-st, has_many, primary_key
-
Andrea Campi
- Tag changed from 2-3-st, has_many, primary_key to 2-3-stable, has_many, primary_key
