DB Transaction happening when adding object in array into an Active Record
I everybody!
I have a little problem :
Let's define thoses objects
class A < ActiveRecord::Base
has_many :bs
def add_some_b(b)
do_som开发者_Python百科e_stuff_with_b(b)
bs << b
end
end
class B < AR
def some_stuff
end
end
When I call this :
some_a_variable.new
some_a_variable.add_some_b(some_b)
I have a transaction opened and immediately closes, nothing happening inside:
[2011-09-01 18:58:49][DEBUG] SQL (0.1ms) BEGIN [2011-09-01 18:58:49][DEBUG] SQL (0.1ms) COMMIT
Why? How can I avoid this?
You're missing the other side of your has_many relationship:
class B < AR
belongs_to :a
def some_stuff
end
end
精彩评论