Doug wrote:
> thanks for the quick response....some follow up questions:
> 
> 1. why get rid of the validation on the has_one side rather than the
> belongs_to?
> 

On the belongs_to side, you can check for a foreign key within the 
object, which is straightforward.  There's no simple way to do it from 
the has_one side.


> 2. why do you call it unnecessary?

Because it serves no actual purpose.  It does not gain you any 
additional functionality or validation.

> 
> the requirement that Foo has a schedule (in my example) and vice-versa
> seems reasonable.
> However, given the above, I don't see how that works with validations.
> 
> How would we satisfy that requirement w/o validations?

Since a Foo is only ever going to have one Schedule, you can create the 
schedule in Foo.new or before_save, or when Foo#schedule is first 
called.

In general, you only need validation on the belongs_to side.

> perhaps a factory method?
> or using a callback on create?
>    where we create a default schedule.
> 

Yes, a callback is a good approach.  Also consider merging the two 
tables -- has_one is a bit smelly.

> thinking out loud here...
> 
> thanks again.

Best,
-- 
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to