I have 3 models right now, Group, User and Asset.
How should I model it such that
- User belongs to Group, Group has many users
- Asset belongs to Group, Group has many asset
- Every User in the Group have access to the asset, for example @user.assets will fetch assets’ info
Thanks.
There’s no need for anything fancy. Basic rails associations between the models will take care of everything.
To have a user access the group’s assets, I’d recommend using
delegate.For more info on
delegatecheck the Rails Guide: Active Support Core ExtensionsUsing delegate allows you to access assets using
@user.assetsas you asked.