http://webwareforpython.org/archives/message/20050602.140855.1524ff2b.en.html#sqlobject-discuss
> > But it would be nice if someone extends SQLObject in this aspect... I
> > think it is a hard problem though because SQLObject internally uses a
> > hidden "id" field as every tables primary key.
>
> An ORM works by mapping a row onto an object using a key function. In
> SQLObject, this must be a single immutable field declared to be the
> primary key. By default, the name of this field is 'id' and it's an
> auto_incrementing integer. You can change the name of the column and
> as of 0.6.1 (or 0.7? I forget) you're not restricted to integer
> primary keys. SQLObject can perform queries on these databases using
> the connection.* methods, but it cannot map them onto objects.

I didn't know about that. In the docs I read that the PK must be
immutable, is that requirement still there? If so, then I don't think
it makes much sense to use another attribute than the hidden 'id' as
the PK.

> If you can't change your tables, you might want to look at SQLAlchemy,
> which does have composite key support but does not have composite
> foreign key support. In practice this means that you have to tweak

Are you implying that it is wrong to use composite primary keys? It is
understandable that SQLObject doesn't have support for them because
not every database even have composite primary keys and they are
probably a PITA to implement. My data model looks like this:

class Network(SQLObject):
    name = StringCol(alternateID = True, length = 100)
    channels = MultipleJoin("Channel")

class Channel(SQLObject):
    name = StringCol()
    network = ForeignKey("Network", notNull = True, cascade = True)

In this example, which models data for an IRC program, each Network
has zero or more Channels, each Channel is a member of a Network. The
PK for Network, is the name attribute - there may not be two Networks
that share the same name. The PK for Channel should be its name and
the network attribute. There may be two Channels with the same name,
but there may not be two Channels with the same name on the same
Network. But you unfortunately can't write that relation using
SQLObject. If Network.channels could be a mutable set instead of a
list, then I think that the data model would work perfectly.

--
mvh Björn


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to