On Wed, Jan 14, 2009 at 3:56 PM, Gordon Allott <[email protected]> wrote: > Hi, > > I have a small problem understanding the join system in storm, If we > take the join example in the tutorial, > ( https://storm.canonical.com/Tutorial#Joins ) it involves a scenario > where there is an Employee table and Company table, employee's reference > companies and it suggest the following code to select companies that the > employee 'Ben' belongs to: > """ >>>> origin = [Company, Join(Employee, Employee.company_id == > Company.id)] >>>> result = store.using(*origin).find(Company, Employee.name.like(u"Ben > %")) > >>>> [company.name for company in result] > [u'Sweets Inc.'] > """ > > Which works great, but in my situation I would have to find more than > one employee, for example, I may need to find the companies that 'Ben', > 'Steve' and 'John' all belong to but am not quite sure how to go about > doing that, just adding more clauses to the find query regarding the > other employee's does not work. > > Thanks, Gord > -- > Gordon Allott ([email protected])
Gordon, There are two different topics that I think your posting touches on. First is the question of who to use a join in a query. The tutorial code you refer to properly demonstrates this. And it sounds like you don't have any trouble getting the table join to work. The second question is how to build a 'where' clause to select the appropriate rows. In the simple example above, you could use the following code to find the companies for Ben, Steve, and Jon: origin = [Company, Join(Employee, Employee.company_id == Company.id)] result = store.using(*origin).find(Company, (Employee.name.like(u"Ben%") | (Employee.name.like(u"Ben%") | (Employee.name.like(u"Ben%") ) ) Note that the pipe operator '|' is shorthand for the more verbose/explicit use of the 'Or' method. result = store.using(*origin).find(Company, Or(Employee.name.like(u"Ben%"), (Employee.name.like(u"Ben%"), (Employee.name.like(u"Ben%") ) ) The use of 'and', 'or' and 'in', to build more complex where clauses is touched upon in the storm manual. (https://storm.canonical.com/Manual) Alex Richardson -- storm mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
