This project is archived and is in readonly mode.
has_many .build does not set reverse reflection
-
Mike Gehard
- Importance changed from to
Here is a failing test for the above situation. Next step is to wade through the code to figure out where to implement the fix. I wanted to get the failing test up here in case someone else with more knowledge of ActiveRecord wanted to fix it. :-)
-
Mike Gehard
Sorry forgot to attach the file...
-
Mike Gehard
One workaround for this is to remove the validates_presence_of :category and rely on a foreign key constraint on category_id (NOT NULL). This is OK as long as you are creating the Thing through the Category because you know that the Category exists because you just created it.
-
Neeraj Singh
- State changed from new to open
- Assigned user set to Neeraj Singh
- Tag set to rails 3, activerecord
I think it is a valid concern. I will take a look at it. It might be a bit tricky but will see how it goes.
-
Neeraj Singh
- State changed from open to resolved
There is another ticket open (can't find right now) which arges that :inverse_of should be the default. Code below fixes the issue
class Car < ActiveRecord::Base has_many :brakes, :inverse_of => :car def self.lab c = Car.new b = c.brakes.build puts b.car end end class Brake < ActiveRecord::Base belongs_to :car, :inverse_of => :brakes def self.lab end end > Car.lab #<Car:0x10203bc38> -
Mike Gehard
Neeraj,
Can you point me in the direction of the commit that fixed this? I would like to take a look to see how you fixed it as a learning experience.
Thanks,
Mike
