activerecord - Querying through several models in Rails 3 -
i have several models:
workspace user asset workspaceuser workspaceasset
workspace has many users , assets, through 2 join tables (workspaceuser, workspaceasset)
i'm trying find efficient , elegant way find out if there exists path between user , asset, ie user -> workspaceuser -> workspace -> workspaceasset -> asset
this have far:
workspace.joins(:workspace_assets, :workspace_users).where("workspace_assets.asset_id = ? & workspace_users.user_id = ?", assetid, userid)
was hoping better solution , perhaps 1 return asset in question.
have tried:
asset.joins(:workspace_assets => {:workspace => :workspace_users}. where("assets.id = ? & workspace_users.user_id = ?", assetid, userid)
Comments
Post a Comment