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

Unnecessary sql query when loading a belongs_to association #2828

Closed
pixeltrix opened this issue Sep 3, 2011 · 4 comments
Closed

Unnecessary sql query when loading a belongs_to association #2828

pixeltrix opened this issue Sep 3, 2011 · 4 comments
Assignees
Milestone

Comments

@pixeltrix
Copy link
Contributor

When loading a belongs_to relationship the association code executes the query even if the foreign key is nil - I think we can safely assume that there isn't a record with a NULL primary key!

@ghost ghost assigned pixeltrix Sep 3, 2011
@tenderlove
Copy link
Member

The primary key name is null, or the value? It seems possible that someone could have a column that allows nulls, even for the primary key.

@pixeltrix
Copy link
Contributor Author

The value is null. I can't say about other databases but I'm sure that MySQL doesn't allow NULL values in a primary key column. I suppose the belongs_to could be pointed to a non-primary key column that allows NULL values but I can't think of any use case for such a scenario.

@thedarkone
Copy link
Contributor

+1 @pixeltrix. I also find the useless WHERE pk_column IS NULL loads annoying.

@jonleighton
Copy link
Member

Sounds good to me. Please feel free to patch :)

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

No branches or pull requests

4 participants