How to get the object array of user table directly through sql association query?

1. Hope result:

[
    {
        "created_at": "Wed Jun 01 00:50:25 +0800 2011",
        "id": 12438492184,
        "name": "love your work.......",
        "user": {
            "id": 1404376560,
            "name": "zaku",
            "url": "http://blog.ceshi.com.cn/zaku"
        },
    },
    {
        "created_at": "Wed Jun 01 00:50:25 +0800 2011",
        "id": 12438492185,
        "name": "love your work.......",
        "user": {
            "id": 1404376561,
            "name": "",
            "url": "http://blog.ceshi.com.cn/zaku"
        },
    },
],

there are tables: article and user
2. Get the desired results by associating the user query. How to write the sql query statement? (note: instead of assembling the query results through foreach, it needs to be done through a sql)

Apr.29,2021

for such json results, you need to set the corresponding output json function in the database class of Python.

< hr >

I dare not send links to my project again. I am always reported by people who are not serious, not careful, or have little knowledge.

if you want to learn sql to sqlalchemy, you can check my profile and find links to related github projects.

Menu