ah, well first I see I did the example wrong, it should be:

    AddressUser.mapper = mapper(
         AddressUser,
         addresses, inherits=User.mapper
      )

and I see you figured that out, the next thing is it needs to have the
tables in a certain order, so apply this patch to
lib/sqlalchemy/mapping/mapper.py :

--- lib/sqlalchemy/mapping/mapper.py
+++ lib/sqlalchemy/mapping/mapper.py
@@ -73,7 +73,7 @@
         if inherits is not None:
             self.primarytable = inherits.primarytable
             # inherit_condition is optional since the join can figure it out
-            self.table = sql.join(table, inherits.table, inherit_condition)
+            self.table = sql.join(inherits.table, table, inherit_condition)
         else:
             self.primarytable = self.table

that will put the "Users" table before the "Addresses" table in its
internal  save ordering.

Adam Ward wrote:
> Hi,
>
> While performing the example listed in the docs (Mapping a Class with
> Table Inheritance) i was unable to get the mapping to work correctly. Is
> this because it is unimplemented, or am I missing something?
>
>>>> a = AddressUser()
>>>> objectstore.commit()
> select nextval('addresses_address_id_seq')
> {}
> INSERT INTO addresses (address_id, user_id, street, city, state, zip)
> VALUES (%(address_id)s, %(user_id)s, %(street)s, %(city)s, %(state)s,
> %(zip)s)
> {'city': None, 'address_id': 1L, 'user_id': None, 'zip': None, 'state':
> None, 'street': None}
> select nextval('users_user_id_seq')
> {}
> INSERT INTO users (user_id, user_name, password) VALUES (%(user_id)s,
> %(user_name)s, %(password)s)
> {'user_id': 1L, 'password': None, 'user_name': None}
>>>> items = AddressUser.mapper.select()
> SELECT addresses.city AS addresses_city, addresses.address_id AS
> addresses_address_id, addresses.user_id AS addresses_user_id,
> users.user_id AS users_user_id, addresses.zip AS addresses_zip,
> addresses.state AS addresses_state, addresses.street AS
> addresses_street, users.password AS users_password, users.user_name AS
> users_user_name
> FROM addresses JOIN users ON users.user_id = addresses.user_id
> {}
>>>> print 'List of addrusers: ', items
> List of addrusers:  []
>
> Most notably the user_id was not set on the addresses table, and the
> users row was created after the addresses.
>
> Adam
>
>
>
>
> -------------------------------------------------------
> 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&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>



-------------------------------------------------------
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&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to