This project is archived and is in readonly mode.
build model on association creates unexpected results
Reported by Bertg | February 9th, 2011 @ 02:06 PM
Say we have this model
class Car < ActiveRecord::Base
# string name
# integer wheels
end
Executing following code
Car.where(:name => "Jeff").new #=> <Car name: "Jeff", wheels: nil>
Car.where(:wheels => [4,8]).new #=> <Car name: nil, wheels: 1>
The first case yield expected result, however the second one does not! 1 wheel?
Car.where(:wheels => 4..8).new #=> <Car name: nil, wheels: nil>
When using a range we don't get the issue.
Test in patch
My suggestion would be to be more careful what values get passed to the scope_for_create (relation.rb:359) method. How this should be achieved, that I do not know.
No comments found
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>