Chaining in Ruby on Rails
Sometimes you need to select obejcts from related table.
Suppose you have User, Assignments and Tasks.
Users have assignments to different tasks with different roles.
Example:
And you need to select open tasks for current user on active "developer" role.
So,you can select user assignments that are active on developer role:
And you can select user opened tasks:
But how to select both?
The standard approach can be used and we select by:
But using this way, you should convert your scopes to arel statements.
It would be good when we can merge those scopes.
And rails already have this possibility. So, rewriting this code we will get:
Quite simple.
