Can't figure out why this would be happening:
class Foo < ActiveRecord::Base
belongs_to :belongable, :polymorphic => true
def after_save
if belongable.kind_of?(User)
send(:some_method)
end
end
end
class Bar < Foo
def some_method
#Do something
end
end
class Group < ActiveRecord::Base
has_many :belongings, :as => :belongable
end
class User < ActiveRecord::Base
has_many :belongings, :as => :belongable
end
The class 'Bar' is an STI model that inherits from Foo (Foo has a 'type' attr). Both Groups and Users are able to have many Bars.
The following works as expected (some_method doesn't get called):
g = Group.create
g.belongings << Bar.new
g.save
The following calls some_method:
Group.first.belongings.first.update_attributes(:attr => :val)
How/Why?! Why isn't the condition in the 'after_save' callback being evaluated once the association already exists?