I have several Models:
Workspace
User
Asset
WorkspaceUser
WorkspaceAsset
Workspace has many users and assets, through the two join tables (WorkspaceUser, WorkspaceAsset)
I’m trying to find the most efficient and elegant way to find out if there exists a path between a User and an Asset, ie User -> WorkspaceUser -> Workspace -> WorkspaceAsset -> Asset
This is what I have so far:
Workspace.joins(:workspace_assets, :workspace_users).where("workspace_assets.asset_id = ? & workspace_users.user_id = ?", assetID, userID)
Was hoping for a better solution and perhaps one that would return the asset in question.
Have you tried: