@yonbergman,
Users model:
// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Users = sequelize.define('users', {
name: {
type: DataTypes.STRING,
},
tags: {
type: DataTypes.JSONB,
defaultValue: {},
},
}, {
tableName: 'users',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Users.associate = (models) => {
Users.hasMany(models.accounts, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'accounts',
});
};
return Users;
};
Users table schema:
-- DDL generated by Postico 1.5.17
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name text,
tags jsonb DEFAULT '{}'::jsonb
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX users_pkey ON users(id int4_ops);
Accounts model:
// This model was generated by Forest CLI. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Accounts = sequelize.define('accounts', {
name: {
type: DataTypes.STRING,
},
}, {
tableName: 'accounts',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Accounts.associate = (models) => {
Accounts.belongsTo(models.users, {
foreignKey: {
name: 'userIdKey',
field: 'user_id',
},
as: 'user',
});
};
return Accounts;
};
Accounts table schema:
-- DDL generated by Postico 1.5.17
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE accounts (
id SERIAL PRIMARY KEY,
name text,
user_id integer REFERENCES users(id)
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX accounts_pkey ON accounts(id int4_ops);
I have no custom code in route files.