Hello,

I'm trying to do create a class with joined inheritance.
 Some have their name in their table and have to access it from another 
table using a join.
I did this mixin and what though it creates an expression error because the 
SQL generated is not the good one.

class NameMixin(object):
    @declared_attr.cascading
    def name(cls):
        if cls.__tablename__ != TABLE_NAME_THROUGH_RELATION:
            return Column(String)

        @hybrid_property
        def name(self):
            return self.basis.name

        @name.expression
        def name(cls):
            return select([OtherTable.__table__.c.name]).select_from(
                cls.__table__.join(OtherTable.__table__)
            )

        @name.setter
        def name(self, new_name):
            self.other_table.name = new_name

        return name


With this Mixin a Column name is created in the  base which I don't want.

I got this error when doing a query on the name:
sqlalchemy.exc.ProgrammingError: (raised as a result of Query-invoked 
autoflush; consider using a session.no_autoflush block if this flush is 
occurring prematurely) 
(psycopg2.ProgrammingError) column "name" of relation "subclass_with_name" does 
not exist

How can I tell sqlalchemy that the base class should not have the column and 
instead make the query using the subtable in different way.

I you guys have any idea, it's welcome (even if it's not the method I'm trying 
to do).
The simpler method would be to replicate the attribute and not do a join, 
though it's less elegant.

Thanks for your help,
Alexis. 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to