Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

build model on association creates unexpected results

#6398

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.

Reported by Bertg · February 9th, 2011 @ 02:06 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

No comments yet.