# Query is not defined

**URL:** <https://community.forestadmin.com/t/query-is-not-defined/6520>\
**Category:** Help me!\
**Tags:** dashboard\
**Created:** [July 21, 2023, 9:28am UTC](https://community.forestadmin.com/t/query-is-not-defined/6520 "2023-07-21T09:28:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nils\_Guicherd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nils_guicherd/32/5327_2.png) [@Nils\_Guicherd](https://community.forestadmin.com/u/Nils_Guicherd)\
**Post date:** [July 21, 2023, 9:28am UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/1 "2023-07-21T09:28:34Z")

</div>

**## Feature(s) impacted**  
Smart charts, sql queries, multiple line charts

**## Observed behavior**  
I figured out how to implement a new route for an API time based chart with the documentation but the request is obliged to be a POST ? Why not a GET ?

See here below my code :

 ![MicrosoftTeams-image (36)](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/a694667cc459d4d35d68db5e4b1526ea8da39018.png)

The query functions as I tested it before in a query chart, but I get only one line.  
**## Expected behavior**  
I want to have a superposition of the users in a time chart. In order to make my dashboard more efficient.

**## Failure Logs**  
This is what I get from the console 🙂

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/c93650ccfd14775c3b0c4e96570831094d0e53fa.png)

Have you any idea why I get this error ?

**## Context**

- Project name: ExplorJob
- Team name: Interface developpers
- Database type: postgre sql

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [July 21, 2023, 10:50am UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/2 "2023-07-21T10:50:52Z")

</div>

Hello @Nils_Guicherd,

> I figured out how to implement a new route for an API time based chart with the documentation but the request is obliged to be a POST ? Why not a GET ?

Indeed the only method we support is a POST for API charts, this was done to allow users retrieving data from the payload body in a way that is secure and follow [conventions](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET).

For your error without looking too much at the code you’ve written, it is simply caused by the fact that `sequelize` is not defined when calling `models.sequelize.query()`.

You should be able to find the right path/object that exports sequelize in `models/index.js`

Best regards,

---

<div class="post-metadata">

**Author:** ![Nils\_Guicherd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nils_guicherd/32/5327_2.png) [@Nils\_Guicherd](https://community.forestadmin.com/u/Nils_Guicherd)\
**Post date:** [July 21, 2023, 1:08pm UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/3 "2023-07-21T13:08:31Z")

</div>

Sorry, but I do not understand your answer. What do I have to do to define `models.sequelize`.

I do not have any new API based chart for me to look for. I read theses [documentation1](https://docs.forestadmin.com/woodshop/how-tos/create-multiple-line-charts#how-to-build-the-expected-json-for-multiple-line-chart) & [documentation2](https://docs.forestadmin.com/documentation/reference-guide/charts/create-an-api-based-chart#time-based-api-based-chart) and tried to combine the two.

My code is likely the same as doc 1.

I also thought about writing a smart chart via builder and try to use liana…fetch() :

```javascript
@action
    async fetchData() {
      const response = await this.lianaServerFetch.fetch('/forest/multiline/users/months', { });
      const result = await response.json();
      this.users = result.data.map(user => {
        const convertedUser = user;
        return convertedUser;
      });
    };

```

Is that a possibility ?

I also asked in a previous post : [post smart chart](https://community.forestadmin.com/t/smart-multiline-chart-struggle/6488) my problems.

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [July 21, 2023, 1:42pm UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/4 "2023-07-21T13:42:36Z")

</div>

You can define a smart chart to handle multiple lines at once since it cannot be done with the components out of the box in FA. But you will still face the issue that `models.sequelize` is not defined.

As shown in the documentation links you have shared, `models` is imported from `models/index.js` at the root of your agent’s code. Your `sequelize` instance should be defined and exported from that file.

I could help you more if you are willing to share the content of the `models/index.js` file but if not you can look at an example project I have made a while back [here](https://github.com/DayTF/smart-relationship/blob/main/models/index.js). It uses multiple connections support and you can see [here](https://github.com/DayTF/smart-relationship/blob/0f235d14754da39f0e752b76c8c94058d6ff0ec6/routes/auth-user.js#L122C1-L122C1) how I fetch the sequelize instance to execute a query.

---

<div class="post-metadata">

**Author:** ![Nils\_Guicherd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nils_guicherd/32/5327_2.png) [@Nils\_Guicherd](https://community.forestadmin.com/u/Nils_Guicherd)\
**Post date:** [July 21, 2023, 1:52pm UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/5 "2023-07-21T13:52:18Z")

</div>

It is from the beginning imported from `../models`

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2d5c3ac4ecd25edd2016fd11eb5a45b77f1e2b20.png)

And my file `models/index.js` is exactly the same as yours : [https://github.com/DayTF/smart-relationship/blob/main/models/index.js](https://github.com/DayTF/smart-relationship/blob/main/models/index.js)

---

<div class="post-metadata">

**Author:** ![anon7284711](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anon7284711](https://community.forestadmin.com/u/anon7284711)\
**Post date:** [July 21, 2023, 2:04pm UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/6 "2023-07-21T14:04:26Z")

</div>

if the file contents are the same in `models/index.js`.  
You should be able to execute your query the same way I did: `models.connections.default.query()`

---

<div class="post-metadata">

**Author:** ![Nils\_Guicherd](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nils_guicherd/32/5327_2.png) [@Nils\_Guicherd](https://community.forestadmin.com/u/Nils_Guicherd)\
**Post date:** [July 21, 2023, 3:25pm UTC](https://community.forestadmin.com/t/query-is-not-defined/6520/7 "2023-07-21T15:25:06Z")

</div>

Thanks ! After multiple tries I managed to get what I wanted 🙂

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/aecf98b496c6a923bb56b37fa6543e23a1234093.png)

Thanks to this snippet of code :

```javascript
 /* Get the Y-axis values */
      var usersProsKeys = _.uniq(records.map((r) => r.userspros));
      var usersExplosKeys = _.uniq(records.map((r) => r.usersexplos));

      /* Build one array per key / line */
      resultsFormated.values.push({
        key: 'usersExlos',
        values: usersExplosKeys
      });
      resultsFormated.values.push({
        key: 'usersPros',
        values: usersProsKeys
      });

```
