Skip to content

Loading…

3.1.0.rc4: Generated create and create! belongs_to association constructors no longer assign new foreign key to parent #1960

Closed
jviney opened this Issue · 3 comments

4 participants

@jviney

In Rails 3.0 using the create_#{association.name} method to construct a belongs_to association resulted in the new foreign key being assigned on the parent record. This no longer happens in Rails 3.1:

class Client < ActiveRecord::Base
  belongs_to :account
end

c = Client.create!
c.create_account!
c.account_id # => nil

I've forked and added a possible fix.

jviney@dd961fb

@jonleighton jonleighton was assigned
@tenderlove
Ruby on Rails member

@jonleighton why is this marked for 3.1.1? Isn't it a regression?

@dtuite

Just thought I'd chime in and say I've experienced the same issue. About half an hour ago I posted a confused question on stackoverflow.

@jonleighton jonleighton added a commit that closed this issue
@jonleighton jonleighton Ensure that the foreign key gets set when doing record.create_associa…
…tion or record.create_association. Fixes #1960.
6d2acc1
@jonleighton
Ruby on Rails member

I thought it didn't need to block 3.1 but that was probably a bad call, and either way I have just pushed a fix. Thanks all.

@bhus bhus pushed a commit that referenced this issue
@jonleighton jonleighton Ensure that the foreign key gets set when doing record.create_associa…
…tion or record.create_association. Fixes #1960.
dfec373
@ttosch ttosch pushed a commit that referenced this issue
@jonleighton jonleighton Ensure that the foreign key gets set when doing record.create_associa…
…tion or record.create_association. Fixes #1960.
d3e56bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.