Thanks nas.  I am surprised that this has not made it to Rails 2.3.2.

On Jul 5, 10:11 pm, nas <[email protected]> wrote:
> There is nothing in rails that can validate an associated record
> exists for a belongs_to relationship.
>
> But you can use Josh Susser's fantastic validates_existence_of plugin
> that does check whether the associated record exists or not
>
> Check out his post here 
> herehttp://blog.hasmanythrough.com/2007/7/14/validate-your-existence
>
> On Jul 5, 8:44 am, Learn by Doing <[email protected]>
> wrote:
>
>
>
> > Jeffrey:
>
> > Thank you.  I tried that but it still didn't work.  So I have this
>
> > class Stat < ActiveRecord::Base
>
> >   belongs_to :user
> >   validates_presence_of   :user_id
> >   validates_associated    :user
>
> > The user table is empty.  I then create a stat with user_id = 99, which
> > does not exist in the user table.  No error is produced:
>
> > Loading development environment (Rails 2.3.2)>> stat = Stat.new(:user_id => 
> > 99)
>
> > => #<Stat id: nil, user_id: 99, ...>
>
> > >> stat.save!
> > => true
>
> > A new record with user_id = 99 was created in the database although the
> > associated user does not exist.  Perhaps this validation only validates
> > the associated user when that user exists.  See 
> > API:http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validat...
>
> > Did I read it right?
>
> > Thanks.
> > --
> > Posted viahttp://www.ruby-forum.com/.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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 [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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to