On Jun 20, 2011, at 12:21 PM, Chris Withers wrote: > Hi All, > > I have the following table: > > CREATE TABLE `ip` ( > `email` varchar(50) NOT NULL, > `ip` varchar(15) NOT NULL, > PRIMARY KEY (`email`,`ip`), > ) > > ...which I'm looking to map to the following class: > > class User: > > def __init__(self,email,*ips): > self.email=email > self.ips = ips > > So, multiple rows in the `ip` table end up mapping to a single user objects. > (ie: I end up with a sequence of ip addresses on user object) > > How do I do it?
I would likely just map traditionally and have "User" be a non-mapped proxy object to a collection of "email/ip" objects. Else if you're looking to make life painful, map User to a view or select() that uses DISTINCT to get just "email" as a row, then a collection of "ip" objects linked on "foreign key". Or just create a "user" table with the same info as that view (i.e. materialize it). -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.