P
P
pcdesign2015-01-23 13:51:35
Python
pcdesign, 2015-01-23 13:51:35

How to query 3 tables in Flask SQLAlchemy?

I am rewriting a site.
And there are quite a lot of this kind of queries to the MySQL database.

SELECT b.id, 
DATE_FORMAT(  b.date  , " %d.%m.%Y " ) AS date, 
b.item_name , c.desc_rus , a.email
FROM users a, user_item b, lang c 
WHERE a.id = ?
AND a.id = b.user_id
AND c.code = b.dest_lang
ORDER BY b.date ASC

Two questions:
1) Is it worth in principle to transfer such queries to SQLAlchemy or is it more correct to process them in raw, that is, as they are?
2) If the 1st item is yes, then how to make such a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ismailov, 2015-01-23
@pcdesign

In general, it would be nice to see the structure, because. the links between the tables are not clear (is there fk there)
Well, if we assume that the query contains a link by fk, then something like this:
Then select the fields that you need.
Second option:
If fk is not specified, then, for example, use add_entity.
It is very difficult to reason here, without knowing how the tables in the database are described, how the models are described in SQLA (go there, it can reflect at all), what kind of load, and so on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question