Thanks for the quick and detailed reply but I guess that I should add a
further information to the discussion. Probably I tried to simplify too
much the problem...
The "mapping" that I have is generated automatically from a multiple
number of UML models. I knew the doc you mention
(http://www.sqlalchemy.org/docs/orm/inheritance.html ) but if I
correctly read your doc it is not enough for my needs. I used the "join"
approach because in many cases I have a python class inheriting from
multiple classes so I followed (with some update to manage "event"s)
your previous discussion here
http://markmail.org/message/ulonbk3hd2rwzzhh#query:sqlalchemy%20multiple%20inheritance+page:1+mid:66l5tgf737nejqis+state:results
---------------------------
mapper(CI_OnlineResource, ci_onlineresource_table)
mapper(MO_OnlineResource, mo_onlineresource_table.join(ci_onlineresource_table))
def MO_OnlineResource_before_insert_listener(mapper, connection, target):
target.ci_onlineresource_type = 'mo_onlineresource'
event.listen(MO_OnlineResource, 'before_insert',
MO_OnlineResource_before_insert_listener)
--------------------------
I used also the approach in
http://www.sqlalchemy.org/docs/orm/mapper_config.html#naming-columns-distinctly-from-attribute-names
changing
mo_onlineresource_table = Table('mo_onlineresource', metadata,
Column('mo_onlineresource_id', Integer,
Sequence('mo_onlineresource_id_seq'), primary_key=True),
Column('function', MO_OnLineFunctionValue.db_type(), nullable=False),
Column('applicationProfile', MO_ApplicationProfileValue.db_type(),
nullable=False),
Column('mo_onlineresource_type', String(30), nullable=False),
extend_existing=False,)
to
mo_onlineresource_table = Table('mo_onlineresource', metadata,
Column('mo_onlineresource_id', Integer,
Sequence('mo_onlineresource_id_seq'), primary_key=True),
Column('mo_function', MO_OnLineFunctionValue.db_type(), nullable=False),
Column('mo_applicationProfile', MO_ApplicationProfileValue.db_type(),
nullable=False),
Column('mo_onlineresource_type', String(30), nullable=False),
extend_existing=False,)
and changing
mapper(MO_OnlineResource, mo_onlineresource_table.join(ci_onlineresource_table))
to
mapper(MO_OnlineResource,
mo_onlineresource_table.join(ci_onlineresource_table), properties={
'applicationProfile': mo_onlineresource_table.c.mo_applicationProfile,
'function': mo_onlineresource_table.c.mo_function
})
but the result is 99% the same
sqlalchemy.exc.InvalidRequestError: Implicitly combining column
mo_onlineresource.mo_applicationProfile with column
ci_onlineresource.applicationProfile under attribute 'applicationProfile'.
Please configure one or more attributes for these same-named columns explicitly.
On 24/10/11 17:25, Michael Bayer wrote:
On Oct 24, 2011, at 11:43 AM, mnagni wrote:
class CI_OnlineResource(object):
def __init__(self):
super(CI_OnlineResource, self).__init__()
self.applicationProfile = None
self.function = None
class MO_OnlineResource(CI_OnlineResource):
def __init__(self):
super(MO_OnlineResource, self).__init__()
self.function = None
self.applicationProfile = None
mapper(CI_OnlineResource, ci_onlineresource_table)
mapper(MO_OnlineResource,
mo_onlineresource_table.join(ci_onlineresource_table))
the above configuration isn't correct - you'd want to use SQLAlchemy's provided
joined table inheritance feature:
mapper(MO_OnlineResource, mo_onlineresource_table, inherits=CI_OnlineResource)
docs: http://www.sqlalchemy.org/docs/orm/inheritance.html
The same-named columns will be rolled under one attribute on the subclass, with
the subclass-table column referenced first. This is the default behavior. To
map the applicationProfile columns distinctly, so that they retain separate
values, link them each to uniquely named attributes as described at
http://www.sqlalchemy.org/docs/orm/mapper_config.html#naming-columns-distinctly-from-attribute-names.
The technique to manually roll columns from a join under an attribute for a
mapping to a join is at:
http://www.sqlalchemy.org/docs/orm/mapper_config.html#mapping-a-class-against-multiple-tables
however when using joined table inheritance these details are handled for you.
the two classes contains the same attributes (function,
applicationProfile) because in "my" specifications is required that
1) MO_OnlineResource.applicationProfile is a String
2) MO_OnlineResource.applicationProfile is an ENUM of String type
So at this moment I have
mo_onlineresource_table = Table('mo_onlineresource', metadata,
Column('mo_onlineresource_id', Integer,
Sequence('mo_onlineresource_id_seq'), primary_key=True),
Column('function', MO_OnLineFunctionValue.db_type(), nullable=False),
Column('applicationProfile', MO_ApplicationProfileValue.db_type(),
nullable=False),
Column('mo_onlineresource_type', String(30), nullable=False),
extend_existing=False,)
ci_onlineresource_table = Table('ci_onlineresource', metadata,
Column('ci_onlineresource_id', Integer,
Sequence('ci_onlineresource_id_seq'), primary_key=True),
Column('applicationProfile', TEXT()),
Column('function', CI_OnLineFunctionCode.db_type()),
extend_existing=False,)
where "db_type" is a @classmethod I use to define the ENUM type.
mapper(CI_OnlineResource, ci_onlineresource_table)
mapper(MO_OnlineResource,
mo_onlineresource_table.join(ci_onlineresource_table))
Obviously running such script I obtain the following error
sqlalchemy.exc.InvalidRequestError: Implicitly combining column
mo_onlineresource.applicationProfile with column
ci_onlineresource.applicationProfile under attribute
'applicationProfile'. Please configure one or more attributes for
these same-named columns explicitly.
Anyone has an idea how get out of this situation?
--
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.
--
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.