On Oct 19, 2011, at 11:44 AM, lestat wrote: > > and use it: > hierarchy_mapper = HierarchyMapper(model_class, model_class.__table__, > non_primary=True) > result = > db.session.query(hierarchy_mapper).from_statement(hie_statement) > > where hie_statement is RAW SQL. > > but I can't add options contains_eager like > result = result.options(contains_eager(Comment.user))
Well no because you're digging way into RECURSIVE queries which SQLA doesn't yet support very nicely. Mapping to them is not a problem that's been cleanly solved. There's some sketches of how to get "with recursive" to work with mappings in such a way that the "recursive" thing is contained within a subquery, you can play with that here: http://www.sqlalchemy.org/trac/attachment/ticket/1859/cte_demo.py > it print error: > ArgumentError: Can't find property 'user' on any entity specified in > this Query. Note the full path from root (Mapper|Comment|comment|non- > primary) to target entity must be specified. > because it non_primary mapper. > > How I can solve this problem? The problem of mapping to CTEs is not a problem that's solved right now. It wouldn't be via subclassing Mapper, though, the code you've pasted there looks most like Mapper so its not clear what portions you've attempted to redefine. if there are areas of mapper loading that could be made more flexible in some way that's definitely useful, we can look into those. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.