Oh, it was so easy!

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,properties={
'action' : relationship(X) # no back_populates, it will never happens anyway
})


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'* ) 

Now I understand... no need for back-ref

Em sábado, 13 de julho de 2013 10h13min50s UTC-3, Alexandre Torres escreveu:
>
> 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?
> Or is there another option , such as declaring action as a property? I 
> tried that, but without much success.
>
> By the way, in my experience (what I can recall), no other ORM tool 
> automatically allows this kind of complex bidirectional behaviour with 
> concrete inheritance ;)
> that would be awesome.
>
>
>

-- 
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/groups/opt_out.


Reply via email to