
Double before/after hook call craziness.
Reported by coryodaniel | July 30th, 2008 @ 10:46 PM
Ok... This is weird and I dont really understand what is happening.
Say you have the following classes:
class User
include DataMapper::Resource
#*** etc, etc ***
before :save do
puts "saving"
end
end
require "lib/path/to/user"
class UserSettings
include DataMapper::Resource
#*** etc, etc ***
end
Given that everything is great, but when you have something like a Dir glob that auto requires all of your classes
Dir.glob("my glob").each {|f| require f}
The double require for user:
1. in the glob
2. in the UserSettings
This does some crazyness. The users class registers each of its before/after callbacks on each require...
Thus, if I do:
user = User.new
user.save
It would output:
"saving"
"saving"
Worse yet, if my after :create were to oh, say create another record in another table, it would create two...
Comments and changes to this ticket
-
coryodaniel July 30th, 2008 @ 11:32 PM
- Tag set to dm-core, holycrap, hooks, require
Nevermind its a ruby bug... yipes => http://opensoul.org/2008/1/9/rub...
-
Dan Kubb (dkubb) November 27th, 2008 @ 07:30 PM
- State changed from new to resolved
- Assigned user cleared.
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.