hi everyone,
in this example I'm going to use a simple has_many :through
association.
Browsing Rails' source I noticed that assigning some objects to a
collection when the record is new and then saving, I can pass every
kind of object, which passes validate_associated or not:
>> @test = Report.new({"document_id"=>nil, "created_at"=>nil,
>> "updated_at"=>nil, "when"=>nil})
=> #<Report id: nil, document_id: nil, when: nil, created_at: nil,
updated_at: nil>
>> @test.reasons << Reason.find_or_create_by_content("pr") # invalid records
>> mass fest, validation will occur on save
=> [#<Reason id: nil, content: "pr", created_at: nil, updated_at:
nil>]
>> @test.save
=> false # all green
On the contrary when the object (owner) is already in place, it bombs
out with an exception.
>> @test = Report.first
=> #<Report id: 1, document_id: 1, ...
>> @test.reasons << Reason.find_or_create_by_content("pr") # ACK
ActiveRecord::RecordInvalid: Validation failed: Content is too short
(minimum is 3 characters)
Nothing strange, I'm sure that's the correct behaviour, what I would
like to ask is if there's some chance to "defer" the assignment, i.e.
acknowledge @test that he will have some reasons but do not raise if
some of them are invalid, leaving the job to update_attributes in
controller.
Would be a patch useful, if currently there are no ways, regarding
this matter?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---