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.

Reply via email to