开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜