[Grok-dev] Re: megrok.rdb updated
faassen at startifact.com
Thu Jun 26 15:56:04 EDT 2008
Calvin Hendryx-Parker wrote:
> Martijn Faassen wrote:
>> * It turns out that using auto-generated primary keys as a container
>> key doesn't look possible: this primary key is not assigned yet by the
>> database by the time the container can be used. This means containers
>> need an important re-think as this destroys the only sensible default
>> behavior I can think of right now. This is a big problem and we need
>> some way around it - there often is no other column in a database
>> table that can function as a key.
> I talked to the #sqlalchemy channel a bit on this and they seem to say
> that auto-generated primary keys isn't the use case for
> MappedCollections. I'm having the same issue in my grok app which isn't
> using megrok.rdb yet, but mimics it quite closely.
Thanks for the info!
Yes, I gathered that MappedCollections and auto-generated primary keys
weren't very friendly to each other. It's a use case for megrok.rdb
containers however to have automatic generation of primary keys. Perhaps
we can find a clever way to do this kind of roundtrips (following
Laurence's hint). Or perhaps it's not a good use case.
> In the end for now I have turned off cascading orphan deletes and handle
> it in my delete methods so I can add a child object then add it to the
> MappedCollection. This works, but is ugly.
> It seems to me that SQLAlchemy should support adding new children to a
> MappedCollection and the collection should handle the save, etc. for
> you. Anyone else have any thoughts on how to get around this?
Well, if SQLAlchemy can't support, we can definitely do the save
ourselves in our megrok.rdb.Container subclass (in the set method).
Perhaps even a special roundtrip to do primary auto-generation if this
is needed. Whether this is a good idea I don't know.
P.S. Feel free to experiment with subclass of megrok.rdb.Container that
does this kind of stuff and please let me know whether it works for you.
More information about the Grok-dev