Skip to content
New issue

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

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

Already on GitHub? # to your account

Ignore has one associations that relies on LIMIT 1 #61

Closed
sobrinho opened this issue Mar 5, 2018 · 2 comments
Closed

Ignore has one associations that relies on LIMIT 1 #61

sobrinho opened this issue Mar 5, 2018 · 2 comments

Comments

@sobrinho
Copy link
Contributor

sobrinho commented Mar 5, 2018

Hi there,

We can almost detect that relies on LIMIT 1 by checking if an order was specified.

Example:

class Order < ApplicationRecord
  has_many :payments
  has_one :last_payment, through: :payments, order: 'paid_at desc'
end

If the order is specified, we are certain that the database may have more than one record.

In that case, we can simply do not auto include because we know that may trigger a problem.

Wdyt?

@jturkel
Copy link
Member

jturkel commented Mar 5, 2018

Sounds reasonable. Want to take a crack at a PR?

@sobrinho
Copy link
Contributor Author

sobrinho commented Mar 5, 2018

Yes, sure!

I will work on this.

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

No branches or pull requests

2 participants