Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting of FK for throgh associations while building #15309

Merged
merged 1 commit into from Jan 2, 2015

Conversation

iantropov
Copy link
Contributor

We should set FK for records, were built via through_associtation when it is possible (through has_one associations).

Fixes #12698

target = through_association.target

if inverse.present? && target.present? && !target.is_a?(Array)
attributes["#{inverse.name}_id"] = target.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would _id always be correct column, or should primary/foreign key method be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am using inverse for this and rely on it.

@iantropov
Copy link
Contributor Author

@egilburg Thanks for comments! I've fixed them, please check.

@egilburg
Copy link
Contributor

thanks!

@rafaelfranca rafaelfranca merged commit 1e0130f into rails:master Jan 2, 2015
rafaelfranca added a commit that referenced this pull request Jan 2, 2015
Add setting of FK for throgh associations while building

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/has_many_through_associations_test.rb
rafaelfranca added a commit that referenced this pull request Jan 2, 2015
Add setting of FK for throgh associations while building

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/has_many_through_associations_test.rb

Conflicts:
	activerecord/CHANGELOG.md
rafaelfranca added a commit that referenced this pull request Jan 2, 2015
Add setting of FK for throgh associations while building

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/has_many_through_associations_test.rb

Conflicts:
	activerecord/CHANGELOG.md
@rafaelfranca
Copy link
Member

Backported as d9d4cd4 and 7d8e56a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

has_many_through_has_one.build does not set the foreign key
3 participants