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

raise ActiveModel::MissingAttributeError when trying to access a relationship without the foreign key attribute #20578

Merged
merged 1 commit into from
Jun 16, 2015

Conversation

dcrec1
Copy link
Contributor

@dcrec1 dcrec1 commented Jun 16, 2015

fixes regression reported on #20253

ActiveRecord::Base#[] was not used cause of 8b95420

@dcrec1 dcrec1 changed the title raise ActiveModel::MissingAttributeError when trying to access a rela… raise ActiveModel::MissingAttributeError when trying to access a relationship without the foreign key attribute Jun 16, 2015
@dcrec1
Copy link
Contributor Author

dcrec1 commented Jun 16, 2015

@sgrif is this ok?

@@ -107,8 +107,7 @@ def target_id
end

def stale_state
result = owner._read_attribute(reflection.foreign_key)
result && result.to_s
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep this as a separate line. This change would cause nil to be turned into a string, which I believe could potentially cause extra queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will change this.

@sgrif
Copy link
Contributor

sgrif commented Jun 16, 2015

One comment, this seems fine otherwise.

…tionship without the foreign key attribute

fixes regression reported on rails#20253

ActiveRecord::Base#[] was not used cause of 8b95420
sgrif added a commit that referenced this pull request Jun 16, 2015
raise ActiveModel::MissingAttributeError when trying to access a relationship without the foreign key attribute
@sgrif sgrif merged commit af01f45 into rails:master Jun 16, 2015
@sgrif
Copy link
Contributor

sgrif commented Jun 16, 2015

Thanks! ❤️

@amatsuda
Copy link
Member

Actually, the original issues was a regression in 4.2.x. Can we backport this patch to 4-2-stable?

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

Successfully merging this pull request may close these issues.

None yet

3 participants