On May 18, 2009, at 8:02 PM, Nathan Harmston wrote:

>
> Hi,
>
> I am trying to map a relation in class which allows it to access
> objects from a couple of tables away ie.
>
> class Zone(object):
>    pass
>
> class Sentence(object):
>   pass
>
> class RawTag(object):
>    pass
>
> class ProcessedTag(RawTag):
>   pass
>
> mapper(RawTag, tag_table)
> mapper(Sentence, sentence_table, "ptags":relation(RawTag,
> primaryjoin
> =and_(sentences_table.c.sentence_id==tag_table.c.sentence_id,
> tag_table_table.c.deleted==0 ), secondary=processed_tag_table) )
> mapper(ProcessedTag, processed_tag_table)
> mapper(Zone, zone_table)
>
> There is a 1:M relation between Document and Sentence and between
> Sentence and RawTag. I want to be able to access all of the
> ProcessedTags for a Zone from the Zone class, I can do this for the
> Sentences table using the "tags" relation that I defined. But I am
> having trouble in allowing the same behaviour for Zone.
>
> So I have tried to use primaryjoin in order to to do this but I am not
> having any luck.
> Among the many exceptions I can generate:
> "ptags":relation(ProcessedTag,
> primaryjoin=and_(and_(sentences_table.c.zone_id ==
> zones_table.c.zone_id,
> sentences_table.c.sentence_id==tags_table.c.sentence_id),
> tags_table.c.deleted==0 ), secondary=processed_tag_table)
>
> UnmappedColumnError: No column sentences.sentence_id is configured on
> mapper Mapper|Zone|zones
>


if you want to make a chained join like that, use just primaryjoin(),  
dont use "secondary", and set viewonly=True.

As an alternative to the above approach, you can also try using  
traditional relations between each class and use the association proxy  
to simplify access from one end to the other.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to