On 19 July 2013 11:32, David <
pie...@workhub.com> wrote:
> Hi,
>
> I discovered a weird behavior when using a "belongs_to: record" association
> in Rails 4.
>
> Given two models A and B:
>
> class A < ActiveRecord::Base
> belongs_to :record, class_name: 'B', foreign_key: 'b_id'
> end
>
> class B < ActiveRecord::Base
> end
>
> When creating A, it inserts a record in B and returns A with id of nil:
>
> irb(main):001:0> A.create!
> (0.1ms) begin transaction
> SQL (0.4ms) INSERT INTO "bs" DEFAULT VALUES
> (2.4ms) commit transaction
> => #<A id: nil, b_id: 1>
>
> A.count # => 0
> B.count # => 1
>
> It used to work in Rails 3.
word 'record' with belongs_to. Is that correct? In other words do