Accessories multimorph2 - multi-morph many-to-many relationships for accessories to users/locations #15539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have some good groundwork in-place for being able to checkout Accessories to both Locations and Users.
But @snipe was looking for the rest of that "connective tissue" to be in place so we can query which accessories are checked out to a User, which accessories are checked out to a Location. Also, from the Accessories side, we will need to be able to see which accessories are checked out to users, which to locations, and also being able to look at checked-out accessories in general, regardless of where they're checked-out-to.
This is the closest I've been able to come to getting something that makes sense here, but I suspect there's a bit more to go.
First off, this establishes the Laravel-standard "morphed-by-many" relationships:
accessories()
method which works how you expect.assignedAccessories()
method (naming is different to explain the difference between "assigned to this location" and "located at this location"). This also works how you expect.locationAssignments()
- which gives which locations this accessory is checked out touserAssignments()
- which gives which users this accessory is checked out to.So that's all the standard stuff, the one weird one I put in was also to accessories, and is called
checkouts()
which gives you the 'interstitial classresults of
AccessoryCheckout` for the accessory in question. Those can be chased down and may include Users as well as Accessories.If I have this right - and it's quite possible that I don't - that last place should be the only place where we need to refer to
AccessoryCheckout
at all - the rest of the relations all return users or locations or accessories as expected.There are plenty of places in the code that still do refer to AccessoryCheckout and probably shouldn't need to - but I wanted to keep this PR small, and understandable, and not conflate different changes.
Most of my testing was with Tinker - making sure that accessories would properly show the appropriate users, locations, or checkouts. And then making sure that locations and users showed the right accessories that were assigned to them.
This should give us the right tooling to re-introduce the "checkout accessory to location" feature, if I've done my job right.