4 ms·
What's the benefit of this approach vs doing scoped queries? i.e. current_user.pages.find(params[:id])
by sbayona573 10y ago
What's the benefit of this approach vs doing scoped queries? i.e. current_user.pages.find(params[:id])
- lfittl 10y agoThe issue is that you would be missing the tenant_id (or user_id) if you were to do `other_object.pages.find(params[:id])` (i.e. on something thats not directly below the user) That is a problem in systems that expect the tenant_id to always be in the query, so you can locate which node the query needs to go to.
- deleted 10y ago[deleted]
- smileysteve 10y agoMy experience is that it's easy for a developer (new or not) to forget to scope some query. So, by using a gem like this or tenancy, your infrastructure prevents the tragic mistake of missing it. A middle ground solution might extend active record to warn you whenever a query doesn't have current_user / current_customer.
- paulddraper 10y ago(1) It makes so you can't forget. (2) Some customers require it. (3) At scale, database sharding becomes necessary. Multi-tenancy is a natural way to shard.