Hi,
Our team is caught with a problem where we need to resave an object
(without validations) in the after :save hook. It isn't working at
all. It would be great to know why a save! from within after :save
doesn't work. I also know that some people are going to respond with
suggestions that we don't use after :save to resave. So, here is a
full descriptions of our needs:
We have a User model with n Emails. We also have on the user, a
foreign key that indicates which email object is primary for that
user. We are using after :save to fill that value to the users first
email, when an email is provided. Here are the important bits of the
models:
class User
property :id, Serial
property :primary_email_id, Integer
has n, :emails, :constraint => :destroy
belongs_to :primary_email, 'Email', :child_key => :primary_email_id
after :save :ensure_email
def email=(address)
# some stuff to set the email
end
def ensure_email
# some logic to determine whether the user has an email that
should be primary
self.primary_email_id = the_id_we_determine
self.save! # yup, no validations needed
end
end
--
You received this message because you are subscribed to the Google Groups
"DataMapper" 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/datamapper?hl=en.