Howto "scope" based on long chains of relationships

What is the best way to make use of the new “scoping” operators and
otherwise search the database using deep relationship chains

Take for example that I want to query what items all customers have ever
bought from one salesman

salesman has-many customers
customers have-many orders
orders have many items

Now I want to write an application which is for the use of only one
salesman who can see only details about their customers and their
orders. Can the new scoping operators help me out here? How would the
scoping be phrased in this case please?

eg in orders/list can we do better than some custom SQL? (limiting to
only orders by the logged in salesman) What about finding the unique
list (and perhaps count) of all items sold (by that salesman)?

Thanks for any pointers

Ed W

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs