On 6/1/15 5:56 AM, Alexis Benoist wrote:
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.
you put one version of the "def name" on the base class and another on
the subclass.
but also, hybrids don't take care of the FROM clause of your SELECT. If
the hybrid attribute assumes a set of tables are present then you need
to say query.select_from() and/or query.join() to add the FROM
expressions that you want.
--
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.