On Friday, November 21, 2014 6:57:54 AM UTC-8, Santiago Doldan wrote:
>
> Thanks for the response Jeremy.
> About the after_rollback, not sure if I'm using that hook correctly but it
> didn't work for me, I have to reset the new value to true before raising
> the Sequel::ValidationFailed exception.
>
So the problem with using an after_rollback model hook is that it isn't
easy to determine what the original state of the model object was. It's
better to add a database after_rollback hook instead a model before_create
hook, so that it is only called on model creation where there is a
subsequent rollback:
DB.create_table(:users){primary_key :id}
class User < Sequel::Model
def before_create
super
db.after_rollback do
@new = true
self.id = nil
end
end
end
u = User.new
u.new? # true
u.id # nil
Sequel::Model.db.transaction { u.save; raise
Sequel::ValidationFailed.new(u) }
u.new? # true
u.id # nil
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.