Re: [SQLObject] Additionnal datas on joins
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Brad B. <br...@bb...> - 2003-07-28 13:40:18
|
On Mon, Jul 28, 2003 at 10:31:01AM +0200, Fran?ois Girault wrote: > Hi all, > > in some cases, there's additionnal datas in relation table. For example, the rank if the relation is ordered, or a lock object for edition... > > It's very common to see that. Yes, this is the use case for composite keys. :) > So I'm thinking about how to implement this : > > - one (ugly but usuable) way to do that without modifying SQLObject is to describe the join like an entity with 2 foreign keys, and then specifying the additionnal columns as usual. I don't know of a way in SQLObject to force two columns to be unique, except to define semantics for composite keys. > - a cleaner way would be to add the columns to the join declaration, and then attach these columns to the entities retrevied when performing the join. > > so, SQLObject guys, what do you think about that ? The cleanest way is to figure out how we want to define composite primary keys. Like this? class SiteMonitor(SQLObject): site = ForeignKey("Site") monitor = ForeignKey("Monitor") _primary_key = (site, monitor) or this perhaps? class SiteMonitor(SQLObject): site = ForeignKey("Site") monitor = ForeignKey("Monitor") PrimaryKey(site, monitor) It would be nice if specifying the primary key looked somewhat like specifying the foreign key (like the latter example), but in other ways, the former example is more SQLObjectish in its use of _foo's for meta information about the table. I think either of these syntaxes would be useable. What do you guys think? -- Brad Bollenbach BBnet.ca |