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

Do not consider optional belongs_to associations when searching for an owner #35

Open
felipefreitag opened this issue Jun 26, 2020 · 1 comment

Comments

@felipefreitag
Copy link
Contributor

Found on TCC:

  • message belongs_to offers_diamond, optional: true
  • message belongs_to offer

Resulting SQL for #index:
"SELECT "messages".* FROM "messages" INNER JOIN "offers_diamonds" ON "offers_diamonds"."id" = "messages"."offers_diamond_id" INNER JOIN "offers" ON "offers"."id" = "offers_diamonds"."offer_id" WHERE "offers"."user_id" = 48 AND "messages"."offer_id" = 41 ORDER BY "messages"."created_at" DESC"

@felipefreitag
Copy link
Contributor Author

It will fail on index, update and delete actions.

Create a scenario where the optional association comes first on the association list. Probably ordered by migration.

https://github.com/SeasonedSoftware/croods-rails/blob/1266790a7a61c0812b7edafb5526452a535d7361/lib/croods/policy/scope.rb#L38

https://github.com/SeasonedSoftware/croods-rails/blob/1266790a7a61c0812b7edafb5526452a535d7361/lib/croods/policy.rb#L67

Reject optional associations: association.options[:optional]

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

No branches or pull requests

1 participant