
Validation when creating resource with belongs_to
Reported by Lawrence Pit | October 28th, 2008 @ 02:37 AM | in 0.10.0
class User
include DataMapper::Resource
property :id, Serial
belongs_to :account
validates_present :account_id
end
a = Account.new(:name => "foo")
u = User.new
u.account = a
u.valid? # return false
There are two issues here:
-
I would prefer to say: validates_present :account
-
u.valid? should return true
Comments and changes to this ticket
-
Dan Kubb (dkubb) January 8th, 2009 @ 02:19 PM
- State changed from new to unconfirmed
- Assigned user cleared.
-
Dan Kubb (dkubb) January 8th, 2009 @ 02:25 PM
- Tag set to dm-validations
- Assigned user set to Michael Klishin (antares)
-
Michael Klishin (antares) March 28th, 2009 @ 10:08 AM
- Milestone set to 0.10.0
- State changed from unconfirmed to accepted
I am pretty sure this has been implemented a while ago, but a few redundant spec examples for dm-validations won't hurt anyway
-
Michael Klishin (antares) March 29th, 2009 @ 10:15 AM
- State changed from accepted to resolved
Just pushed example for association validation. Spec suite only has n:1 right now but validator uses @ivar so it should work identically.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »