Forum: Ruby on Rails How to Validate Child Object Virtual Attribute against Parent Object Field?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
djfobbz (Guest)
on 2008-11-28 11:35
(Received via mailing list)
Ok, I have the following:

Account => has_many => Users
Users => belong_to => Account

When an Account is created, an 'account_code' is also generated and
stored within the Accounts table.  Users must use this 'account_code'
in order to Signup for the service.  My problem is how do I compare
the User submitted 'account_code' in the Signup form against the
'account_code' stored in the parent object Account?  Do I define this
'account_code' as a virtual attribute to the User model?  Also, once I
make the comparison, in case there is a mismatch, how do I add the
error along with all other errors relating to User model?
This topic is locked and can not be replied to.