.. sourcecode:: python+sql
+ from sqlalchemy.orm import mapper
from sqlalchemy.sql import join
class AddressUser(object):
'user_id': [users_table.c.user_id, addresses_table.c.user_id]
})
-A second example:
+Note that the list of columns is equivalent to the usage of :func:`.column_property`
+with multiple columns::
-.. sourcecode:: python+sql
+ from sqlalchemy.orm import mapper, column_property
+
+ mapper(AddressUser, j, properties={
+ 'user_id': column_property(users_table.c.user_id, addresses_table.c.user_id)
+ })
- from sqlalchemy.sql import join
+The usage of :func:`.column_property` is required when using declarative to map
+to multiple columns, since the declarative class parser won't recognize a plain
+list of columns::
+
+ from sqlalchemy.ext.declarative import declarative_base
+
+ Base = declarative_base()
+
+ class AddressUser(Base):
+ __table__ = j
+
+ user_id = column_property(users_table.c.user_id, addresses_table.c.user_id)
+
+A second example::
+
+ from sqlalchemy.sql import join
# many-to-many join on an association table
j = join(users_table, userkeywords,
which instructs the mapper to keep both of those columns set at the same
value.
+
Mapping a Class against Arbitrary Selects
------------------------------------------