Note that this article was written before the introduction of extends, which would likely make this type of modeling much easier. You can read about extending explores and views here.
If you are looking for a way to create user-specific data restrictions through filters, check out access filter fields.
Looker model permissions can be used to limit user access to specific models, but using this feature to limit users to specific sets of dimensions and measures may not be ideal. You can create one model for each set of fields that you want to make available to each set of users. However, this can be difficult to maintain when changes are made to a field definition, because the definition needs to be manually changed in every model you create.
We can make this easier by using
sets within view files. This is a way to keep all the models "synced" while easily maintaining field restrictions.
Let's start with three example models: thelook, thelook_marketing, and thelook_support:
The only difference between these models is that thelook_marketing and thelook_support have an extra
These two included files (set_marketing.set.lookml and set_support.set.lookml) are simply empty views with set definitions inside them. There is one set for every explore, which contains the fields that should be available for that explore.
In this example, the support model will end up seeing more fields than the marketing model:
Next, join the set-containing view to each explore of the model as shown below. Using
join all by itself, without a parameter like
sql_on, is unusual and wouldn't work in most cases. It's ok in this case, because its only purpose is to expose the appropriate sets to each explore. Finally, limit each explore to the appropriate set by using the
Now, only the fields specified in the set for each explore will be exposed when exploring data.
Marketing users will see:
While support users will see:
Now if we change anything in both models, we can just copy and paste all the code between each model. We don't have to worry about overwriting any of the field restriction logic, which is now isolated to the set files.