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

Move Transfer.storage_locations_transferred_to/from_in to StorageLoca… #4733

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coalest
Copy link
Contributor

@coalest coalest commented Oct 23, 2024

(Doesn't resolve any issue)

Description

While working on something else, I noticed this Transfer class method that seemed odd in that it returns an array of StorageLocation ActiveRecord objects. Feels like it belongs more on the StorageLocation model. Moving it also simplified the method logic.

Also fixed the association's foreign_key so that ActiveRecord can join the table correctly.

Type of change

Refactor

How Has This Been Tested?

Moved model spec from Transfer to StorageLocation.

@cielf cielf requested a review from dorner October 23, 2024 16:32
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

I agree with the move. One comment about the implementation.

@@ -77,6 +77,14 @@ def self.items_inventoried(organization, inventory = nil)
end
end

def self.with_transfers_to(organization)
joins(:transfers_to).where(organization_id: organization.id).distinct.order(:name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You shouldn't need the where clause since the transfer has a from_id and to_id which powers the association.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without the where clause, wouldn't we be grabbing every storage location that has at least one transfer from/to that location? Don't we only want the storage locations related to a certain organization?

Screenshot from 2024-10-28 13-30-41

Copy link
Collaborator

Choose a reason for hiding this comment

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

Storage locations belong to an organization and so do transfers. So if you have a transfer, by definition only storage locations belonging to the same organization can be involved in it.

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.

2 participants