On Jul 13, 2013, at 9:13 AM, Alexandre Torres <[email protected]> wrote:
> Hi again, > > I implemented a relationship using back_populates using the example > http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#relationships-with-concrete-inheritance > > But I stumbled in a problem: My super class A does not have a table, it is > based in a polymorphic union (thanks Michael for the great tip in my last > post). > > X<->A > A <-- L1 > A<--L2 ... > > XMapper = mapper(X, C_table, properties={ > 'resources': relationship(A,collection_class=set,back_populates='action')}) > > AMapper = mapper(A,pjoin,with_polymorphic=('*', > pjoin),polymorphic_on=pjoin.c.type) > > L1Mapper = mapper(L1,L1_table,inherits=AMapper, > concrete=True, > polymorphic_identity='l1',properties={ > 'action' : > relationship(X,primaryjoin=(X_table.c.id==L1_table.c.id_idx),back_populates='resources' > ) > #... (L2 is pretty much the same) > > This produces an error because my A mapper does not implement the resources > relationship: > "sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper|A|pjoin' has no property > 'action'" > But If I remove the first back_populates='action', it works. Well, for a read > only collection... > My question is this: is there a way to make SQLAlchemy understand that class > A is abstract and therefore does not implements the relationship? SQLAlchemy already understands that class A is abstract, and if it doesn't have the relationship that is also fine, but then there's nothing to point a "back populates" towards. If you want a "back populates" then you have to make the "action" relationship on your base class. This is possible, you'd just have to get it to be in terms of the polymorphic selectable youre mapping to on the abstract class. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
