
Bug: overriding query condition of collection via #build method.
Reported by Lawrence Pit | October 29th, 2008 @ 06:23 AM
model Account
has n, :people
end
Account.get(1).people.build(:first_name => "x", :last_name => "y", :account_id => 2).save
this will insert a person belonging to the account with id 2.
~ INSERT INTO `people` (`account_id`, `updated_at`, `last_name`, `created_at`, `first_name`) VALUES (2, '2008-10-29 22:13:45', 'y', '2008-10-29 22:13:45', 'x')
I would consider this a bug. You should not be able to override the query conditions of the collection using the #build method.
Comments and changes to this ticket
-
Dan Kubb (dkubb) December 1st, 2008 @ 02:29 AM
- Assigned user changed from Sam Smoot to Dan Kubb (dkubb)
- State changed from new to open
-
Dan Kubb (dkubb) December 4th, 2008 @ 03:54 AM
- State changed from open to accepted
-
Dan Kubb (dkubb) May 16th, 2009 @ 01:16 AM
- State changed from accepted to not-applicable
I'm just reviewing older tickets and came across this one.
Actually, this behavior is intended. If you go through the trouble of creating a collection, any resources created within the collection will be forced to inherit it's scope. If you don't want to use the inherited scope, then you would want to be using Person.new.
This behavior should be consistent when using #create, #new, #first_or_new, and #first_or_create within the scope of a Model, Collection, One to Many, or Many to Many Associations.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »