it maps against multiple tables no problem as long as all the other columns in them contain proper data; whats missing is the extra step to automatically synchronize newly generated primary keys from one table to foreign keys in the other. theres a method in place that takes join criterion and works out "sync rules" from them, so that just needs to be appropriately plugged in. it might be able to pull them from the join automatically but more complex queries might not be so obvious as to what the criterion is.

the zblog demo has an example of mapping against multiple tables, it maps "Post" objects against a join of the "posts" table against an aggregate count of the "comments" table with some extra GROUP BY stuff worked in, so that when you get the list of posts you also get the count of comments for each post...but it only saves to the "posts" table. when a table in the select statement does not have all of its primary key columns represented, its a read only table, and isnt affected upon save. so id characterize this feature not as "broken" but "incomplete".

anyway, this isnt so tough, ticket 191 is up to remind me to get around to this sometime this week (back to work tomorrow !)

On May 29, 2006, at 8:14 PM, Jamie Wilkinson wrote:

This one time, at band camp, Michael Bayer wrote:
you can hack this with a MapperExtension after_insert rule that sets
the "account_id" field on the Person object after the "account" table
is inserted.  a little ugly but probably would work right now.

I'll try the hack now and let you know how it goes.

right now, the mapper youve made considers the primary key of of
Person to be (person.id, account.id).  it doenst have any notion of
the join between them being synchronized.

Right, that's ok. If you look at the engine dump I posted you'll see that
the join failed anyway because the foreign key wasn't being set, so
regardless of what the mapper thinks the primary key is, it wasn't going to
work.

the pattern youre using is also 99% similar to a plain inheritance
pattern except you have just one class.

Well, as mentioned earlier, it's a pattern described in "Mapping a Class against Multiple Tables" in the "Advanced Data Mapping" chapter of the docs
;-)

So, either this is a bug in the documentation because SA *can't* do this, or
it's a bug in SA because it's supposed to do it.  Your next comment:

this would suggest that providing an external API to build up the
same "synchronization" rules that joined inheritance uses could be
whats needed, something along the lines of:

suggests that you're thinking the latter. Or have I misread you, and you're trying to solve the extra where clause problem but not the broken example?

        mapper(Person, join(account, person), properties = {
       'id' : person.c.id,
       'handle': person.c.handle,
       'firstname': person.c.firstname,
       'lastname': person.c.lastname,
       'email_address': account.c.email_address,
       'password': account.c.password,
       }
        synchronize=[account.c.id==person.c.account_id]
        )

I think I can also get the order of "account", "person" to be sorted
automatically....

Yeah, I thought you'd already got code that worked out the dependency order
so I was surprised when I first saw that ;-)

Tell you what, I'll write some unit tests and post them here.


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel? cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to