[storm] Does one have to create the one-to-many ref. is it's not neede in the object?
Gabriel Rossetti
gabriel.rossetti at arimaz.com
Tue Jul 22 14:56:17 BST 2008
James Henstridge wrote:
> On Tue, Jul 22, 2008 at 6:15 PM, Gabriel Rossetti
> <gabriel.rossetti at arimaz.com> wrote:
>
>> Hello everyone,
>>
>> I am following the official tutorial and I have a small question.
>> In the one-to-many reference type, does it have to be defined if I don't
>> need the attribute? If I created my database with a "user" and a "lang"
>> table, their is a one-to-many relationship in between them, but in my
>> python objects, the "User" object needs a one-to-one ref to the "Lang"
>> class/table, but I don't need a ref to the "User" from the "Lang" class.
>> Does Storm need for me to put it there so it knows how everything comes
>> together? Here are the Tables :
>>
>
> If you don't need to use the ReferenceSet() in your code, you should
> be able to leave it out of your table definition.
>
>
Ok, thank you!
>> User(id, fname, lname, lang_id)
>> Lang(id, name)
>>
>> where "id" are primary keys and "lang_id" is a foreign key, and the
>> classes are defines as the following :
>>
>> class User(object):
>> __storm_table__ = "user"
>>
>> id = Int(primary=True)
>> fname = Unicode()
>> lname = Unicode()
>> langId = Int()
>>
>
> You should either name this variable lang_id, or use Int("lang_id") if
> you want this to match up with your table definition.
>
>
Yes, small typo/omission on my part, thanks
>> lang = Reference(langId, Lang.id)
>>
>
> You can probably use the following to do a forward reference here:
>
> lang = Reference(lang_id, 'Language.id')
>
>
But then my classes have to inherit from the Storm base class (if I use
the string ref)
>> class Language(object):
>> __storm_table__ = "lang"
>>
>> id = Int(primary=True)
>> name = Unicode()
>> # users = ReferenceSet(id, User.id)
>>
>> Thank you,
>> Gabriel
>>
>
>
> James.
>
Gabriel
More information about the storm
mailing list