[storm] Error when performing a find
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Thu Jul 24 16:05:38 BST 2008
James Henstridge wrote:
> On Thu, Jul 24, 2008 at 7:18 PM, Gabriel Rossetti
> <gabriel.rossetti at arimaz.com> wrote:
>
>> Hello everyone,
>>
>> I am playing around with twisted, using the tutorial's Employee, Company
>> & such as a base. I tried doing a find like this :
>>
>> emp = store.find(Employee, Employee.company.name == u"circus")
>>
>> but I get this exception
>>
>> AttributeError: 'Reference' object has no attribute 'name'
>>
>> Can I not do this or am I doing it wrong?
>>
>> If I do : bob.company.name it returns u"circus", as it should.
>>
>
> You need to structure your query like:
>
> store.find(Employee, Employee.company == Company.id, Company.name ==
> u"circus")
>
> James.
>
Thanks for your reply James, I though the reference sent back the while
object and it mapped the id's (primary keys) together? I guess if you
don't specify the member/attribute it sends back the primary key? I
added a Language class and added the language_id and ref to the Person
like so :
class Language(object):
__storm_table__ = "language"
id = Int(primary=True)
name = Unicode()
def __init__(self, name):
self.name = name
english = store.add(Language(u"ENGLISH"))
french = store.add(Language(u"FRENCH"))
class Person(object):
__storm_table__ = "person"
id = Int(primary=True)
name = Unicode()
language_id = Int()
language = Reference(language_id, Language.id)
and I added the column in the employee table (and I had to add a person
table because it complained, even though before it never had) tried this :
>>> s = store.find(Employee, Employee.language == Language.id)
>>> s.count()
0
>>> s = store.find(Employee, Employee.language_id == Language.id)
>>> s.count()
3
and it doesn't seam to always be true, could you explain why?
Also, is there a difference in between these two constructs :
>>> s = store.find(Employee, Employee.language_id == Language.id,
Language.name == u"ENGLISH")
>>> s = store.find(Employee, (Employee.language_id == Language.id) &
(Language.name == u"ENGLISH"))
it seams to me there isn't.
Thank you,
Gabriel
More information about the storm
mailing list