SQLAlchemy Build selectable query with multiple tables
<p>I created a materialized view for my flask web application with the help of
<a href="http://www.jeffwidman.com/blog/847/using-sqlalchemy-to-create-and-manage-postgresql-materialized-views/" rel="nofollow">Jeff Widman</a>.</p>

<p>Unfortunately he only describe how to join two tables. I would like to create a materialized view with more than two tables.</p>

<pre><code>class AnalyticV(MaterializedView):
  __table__ = create_mat_view("my_view",
                             db.select([Table1.id.label('id'),
                                        Table1.title.label('title'),
                                        Table2.location.label('loc'),
                                        Table3.time.label('time'),]
                             ).select_from(db.join(Table1, Table2, isouter=True) )
                             )
</code></pre>

<p>How can I insert a second </p>

<pre><code>select_from(db.join(Table1, Table3, isouter=True))
</code></pre>

<p>Table1 has two relationships to Table2 and Table3</p>

<p>The SQL should look like this:</p>

<pre><code>SELECT Table1.id AS id,
       Table1.title AS title,
       Table2.location AS loc,
       Table3.time AS time 
FROM Table1 LEFT OUTER JOIN Table2 ON Table2.id = Table1.table2_id
LEFT OUTER JOIN Table3 ON Table3.id = Table1.table3_id
</code></pre>

<p>Just add another join</p>

<pre><code>select_from(db.join(Table1, Table2, isouter=True).join(Table3, isouter=True)) 
</code></pre>

python sqlalchemy flask-sqlalchemy