Hello,

I want to use a table and ORM for keeping and managing tree of static web 
pages with MPTT approach. The class/table itself is rather simple:

class Node(db.Model):
    __tablename__ = 'node'
    id = db.Column(db.Integer, primary_key = True)
    parent_id = db.Column(db.Integer, db.ForeignKey(id))
    name = db.Column(db.String(150), nullable = False)
    urlname = db.Column(db.String(150), nullable = False)
    lft = db.Column(db.Integer, nullable = False)
    rgt = db.Column(db.Integer, nullable = False)

here urlname is the part of full URL a page has, e.g. if we have a page 
Presentations with a list of presentations, with parent page Library and 
available at '/library/presentations', the 'urlname' for this record will 
be 'presentations' and urlname for the parent page, Library, will be 
'library'. However in this case, every time I need a full URL to the page I 
have to make a query to get it. In standard SQL I can get a list of pages 
with pseudo field 'url' as following:

select n1.name, (select group_concat(n2.urlname SEPARATOR '/') from node n2 
where n2.lft <= n1.lft  and n2.rgt >= n1.rgt order by n2.lft asc) as url 
from node n1 

Is there any way to make SQLAlchemy select this pseudo field automatically 
every time I make a query or fetch an object? Say I do something like n = 
Node.query.filter(name = 'Presentations') and then just use n.url?  

Thanks a lot in advance for any hints!

Sergey
 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/lUOjshXTJbIJ.
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.

Reply via email to