Changeset 7824
- Timestamp:
- 10/10/07 06:45:13 (1 year ago)
- Files:
-
- trunk/activerecord/lib/active_record/associations.rb (modified) (1 diff)
- trunk/activerecord/test/associations_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/db_definitions/schema.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/developer.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/associations.rb
r7813 r7824 1073 1073 association = instance_variable_get("@#{association_name}") 1074 1074 1075 if association.respond_to?(:loaded?) && association.loaded? 1076 if @new_record_before_save 1077 records_to_save = association 1078 else 1079 records_to_save = association.select { |record| record.new_record? } 1080 end 1075 records_to_save = if @new_record_before_save 1076 association 1077 elsif association.respond_to?(:loaded?) && association.loaded? 1078 association.select { |record| record.new_record? } 1079 else 1080 [] 1081 end 1082 1083 if !records_to_save.blank? 1081 1084 records_to_save.each { |record| association.send(:insert_record, record) } 1082 1085 association.send(:construct_sql) # reconstruct the SQL queries now that we know the owner's id trunk/activerecord/test/associations_test.rb
r7767 r7824 102 102 end 103 103 104 def test_save_on_parent_saves_children 105 developer = Developer.create :name => "Bryan", :salary => 50_000 106 assert_equal 1, developer.reload.audit_logs.size 107 end 104 108 end 105 109 trunk/activerecord/test/fixtures/db_definitions/schema.rb
r7119 r7824 76 76 end 77 77 end 78 79 create_table :audit_logs, :force => true do |t| 80 t.column :message, :string, :null=>false 81 t.column :developer_id, :integer, :null=>false 82 end 78 83 end trunk/activerecord/test/fixtures/developer.rb
r7504 r7824 42 42 has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id' 43 43 44 has_many :audit_logs 45 44 46 validates_inclusion_of :salary, :in => 50000..200000 45 47 validates_length_of :name, :within => 3..20 48 49 before_create do |developer| 50 developer.audit_logs.build :message => "Computer created" 51 end 52 end 53 54 class AuditLog < ActiveRecord::Base 55 belongs_to :developer 46 56 end 47 57