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
AO3-5023 Fix collections displaying too many times for works #2940
AO3-5023 Fix collections displaying too many times for works #2940
Conversation
…-5023_rails_4_dot_2_bugfix
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::REJECTED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::APPROVED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::APPROVED, | ||
collection_approval_status: CollectionItem::APPROVED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::REJECTED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::APPROVED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
.where( | ||
collection_items: { | ||
user_approval_status: CollectionItem::APPROVED, | ||
collection_approval_status: CollectionItem::APPROVED | ||
} | ||
) | ||
.references(:collection_items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place the . on the previous line, together with the method call receiver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the changes in the works controller might be causing two test failures -- I restarted the build on Travis, but it unfortunately still failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, thank you!
Pull Request Checklist
AO3-1234 Fix thing
)Issue
https://otwarchive.atlassian.net/browse/AO3-5023
Purpose
What does this PR do?
This PR fixes the issue where the same collection was showing up multiple times on a given work's collections page.
The first fix is using
.includes
instead of.joins
in collection scopes that should return collections (not collection items) based on their approval status.This raised a bug caused by queries in the collections and works controllers that use
.includes(:approved_collections)
, which is including a scoped set of collections based on a join table in the includes - this tends to blow up when combined with other scopes. I've fixed this by explicitly spelling out how the:approved_collections
work - to.includes(collections: [:collection_items]).where(collection_items: { user_approval_status: CollectionItem::APPROVED, collection_approval_status: CollectionItem::APPROVED })
.Work.includes(:approved_collections).references(:collection_items)
will run the expected query (although that could cause some confusion because it's not precisely clear why thereferences(:collection_items)
has to be there without context).Work.includes(:approved_collections).references(:item_collections).in_collection(@collection)
(and other variations, rearranging the order the methods are chained in or adding different scopes like the ones present in the two controllers) blow up with the errorActiveRecord::AssociationNotFoundError: Association named 'collection_items' was not found on CollectionItem
. I'm happy to talk more about this if there are concerns with the solution in this PR.Testing
How can the Archive's QA team verify that this is working as you intended? (If you have access, please copy this into the JIRA ticket for them!)
Locally -
In staging - go to http://test.archiveofourown.org/works/1064145/collections and ensure that the collection ModeratedUnrevealedTwoWorks shows up only once.
References
Are there any other relevant issues / PRs / mailing lists discussions related to this?
Credit
What name do you want us to use to credit your work in the Archive of Our Own's Release Notes?
Wendy Randquist - Littlelines
What pronouns do you prefer (she/her, he/him, zie/hir etc)?
she/her
(if you do not fill this in, we will use your GitHub account name and will use "they" to avoid making assumptions about your gender)