例を見てみましょう:
class Subscription < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :subscriptions
end
u1 =User.new
s1 = Subscription.new
私によると、次の2行は同等である必要があります。
u1.subscriptions << s1, and
s1.user = u1
しかし、そうではないようです。1 行目の実行後、u1.subscriptions_ids は [1] を返しますが、2 行目の実行後、u1.subscriptions_ids は [] を返します。
この理由は何でしょうか?