Re: [SQLObject] Objects with localized properties
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ian B. <ia...@co...> - 2003-05-07 18:00:39
|
On Wed, 2003-05-07 at 12:38, deelan wrote: > to clarify as DB schema i was thinking to something > like this: > > Product table > ProductId > ... > > ProductName table > ProductId > Name > Lang > > where "lang" is out 2 char lang code, this would require > a join between the two tables, by doing this i will avoid to > mess up things when i need to add a name with a new > localization. if i understood correctly via sqlobject i can > auto join the two tables. i need to use one of those Join > objects, is this correct? Yes, that's probably an easier layout too. In this case a join doesn't seem quite right... hmmm... you might do: class Product(SQLObject): _joins = [MultipleJoin('ProductName')] def name(self, lang): return ProductName.selectBy( productID=self.id, lang=lang)[0].name class ProductName(SQLObject): productID = KeyCol(foreignKey='Product') name = StringCol() lang = StringCol(length=2, varchar=False, notNone=True) Some might say that ProductName doesn't need a primary key (productID + lang is unique, and a compound key). My response is always: then it should be a join. Maybe that's true in this case, i.e., some new LangJoin(...). I'll think about this. Creating a specific join of this type is still mostly theoretical -- I haven't actually done one, and I don't know if anyone else has either. Ian |