Strapi querying data only belongs to user

Viewed 264

New to Strapi and I feel this question is very trivial but I can't figure it out.

I'm trying to create a query in the companies controller that only returns companies that belongs to the authenticated user. (default is return all companies in the database)

Thanks in advance

const entities = await strapi.query('companies').model.query(c => {c.where({users_permissions_users: { id: 1 }})}).fetch()
error: column "users_permissions_users" does not exist
Companies.js
{
    "id": 2,
    "company_name": "Tesla",
    "description": null,
    "url": null,
    "email": null,
    "location": null,
    "employees": null,
    "created_at": "2020-10-28T05:24:47.487Z",
    "updated_at": "2020-10-28T05:24:47.528Z",
    "job": null,
    "logo": null,
    "users_permissions_users": [
      {
        "id": 1,
        "username": "spongebob",
        "email": "spongebob@email.com",
        "provider": "local",
        "confirmed": true,
        "blocked": false,
        "role": 1,
        "created_at": "2020-10-14T20:48:59.610Z",
        "updated_at": "2020-10-28T05:24:47.521Z",
        "company": 2,
        "firstName": null,
        "lastName": null,
        "employer": null
      }
    ]
}
0 Answers
Related