Displaying 1 result from an estimated 1 matches for "create_carriage".
2010 May 11
1
has_one/belongs_to -- accessing the subordinate
...overed an oddity while trying it.
F''rinstance, if every horse has a carriage:
============
ActiveRecord::Schema.define do
  create_table(:horses) {|t| t.timestamps }
  create_table(:carriages) {|t| t.timestamps; t.integer :horse_id }
end
class Horse < ActiveRecord::Base
  after_create :create_carriage
  has_one :carriage, :dependent => :destroy
  private
    def create_carriage
      Carriage.create(:horse => self)
    end
end
class Carriage < ActiveRecord::Base
  belongs_to :horse
end
============
This works fine using create:
========
>> horse1 = Horse.create()
=> #<Horse...