Hello Lamatt,
Here is Postgres dump for the table (account):
--
-- Name: account; Type: TABLE; Schema: public; Owner: arne
--
CREATE TABLE public.account (
description text,
id integer DEFAULT nextval('public.id_seq'::regclass) NOT NULL,
functions public.account_function[],
plan_id integer,
type integer,
number text,
vat_group_id integer
);
ALTER TABLE public.account OWNER TO arne;
--
-- Name: account account_pkey; Type: CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT account_pkey PRIMARY KEY (id);
--
-- Name: account account_type_fkey; Type: FK CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT account_type_fkey FOREIGN KEY (type) REFERENCES public.option(id);
--
-- Name: account ct_fk_account_plan; Type: FK CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT ct_fk_account_plan FOREIGN KEY (plan_id) REFERENCES public.account_plan(id);
--
-- Name: account ct_fk_vat_code; Type: FK CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT ct_fk_vat_code FOREIGN KEY (vat_group_id) REFERENCES public.tax_group(id) ON UPDATE CASCADE;
--
-- PostgreSQL database dump complete
--
I do the same for the referring table (organization):
--
-- Name: organization; Type: TABLE; Schema: public; Owner: arne
--
CREATE TABLE public.organization (
id integer DEFAULT nextval('public.id_seq'::regclass) NOT NULL,
name text,
url text,
description text,
"group" text,
plan_id integer,
country_id integer,
xtra jsonb,
organization_number text
);
ALTER TABLE public.organization OWNER TO arne;
--
-- Name: organization organization_pkey; Type: CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.organization
ADD CONSTRAINT organization_pkey PRIMARY KEY (id);
--
-- Name: organization ct_fk_account_plan; Type: FK CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.organization
ADD CONSTRAINT ct_fk_account_plan FOREIGN KEY (plan_id) REFERENCES public.account_plan(id);
--
-- Name: organization organization_country_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: arne
--
ALTER TABLE ONLY public.organization
ADD CONSTRAINT organization_country_id_fkey FOREIGN KEY (country_id) REFERENCES public.area_country(id);
--
-- PostgreSQL database dump complete
--
Here is model account.js:
// This model was generated by Lumber. 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 Account = sequelize.define('account', {
description: {
type: DataTypes.STRING,
},
functions: {
type: DataTypes.ARRAY(DataTypes.ENUM(
'cash_account',
'vat_account',
'cash_account',
)),
},
number: {
type: DataTypes.STRING,
},
}, {
tableName: 'account',
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.
Account.associate = (models) => {
Account.belongsTo(models.option, {
foreignKey: {
name: 'typeKey',
field: 'type',
},
as: 'type',
});
Account.belongsTo(models.accountPlan, {
foreignKey: {
name: 'planIdKey',
field: 'plan_id',
},
as: 'plan',
});
Account.belongsTo(models.taxGroup, {
foreignKey: {
name: 'vatGroupIdKey',
field: 'vat_group_id',
},
as: 'vatGroup',
});
Account.hasMany(models.organizationAccounts, {
foreignKey: {
name: 'accountIdKey',
field: 'account_id',
},
as: 'organizationAccounts',
});
Account.hasMany(models.organizationAccounts, {
foreignKey: {
name: 'accountIdKey',
field: 'account_id',
},
as: 'organizationAccounts',
});
Account.hasMany(models.verificationRow, {
foreignKey: {
name: 'accountIdKey',
field: 'account_id',
},
as: 'verificationRows',
});
Account.hasMany(models.verificationRow, {
foreignKey: {
name: 'accountIdKey',
field: 'account_id',
},
as: 'verificationRows',
});
Account.hasMany(models.accountBalance, {
foreignKey: {
name: 'accountIdKey',
field: 'account_id',
},
as: 'accountBalances',
});
};
return Account;
};
Here is the same for organization:
// This model was generated by Lumber. 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 Organization = sequelize.define('organization', {
name: {
type: DataTypes.STRING,
},
url: {
type: DataTypes.STRING,
},
description: {
type: DataTypes.STRING,
},
group: {
type: DataTypes.STRING,
},
xtra: {
type: DataTypes.JSONB,
},
organizationNumber: {
type: DataTypes.STRING,
},
}, {
tableName: 'organization',
underscored: true,
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.
Organization.associate = (models) => {
Organization.belongsTo(models.accountPlan, {
foreignKey: {
name: 'planIdKey',
field: 'plan_id',
},
as: 'plan',
});
Organization.belongsTo(models.areaCountry, {
foreignKey: {
name: 'countryIdKey',
field: 'country_id',
},
as: 'country',
});
Organization.hasMany(models.user, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'users',
});
Organization.hasMany(models.user, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'users',
});
Organization.hasMany(models.organizationAccounts, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'organizationAccounts',
});
Organization.hasMany(models.organizationAccounts, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'organizationAccounts',
});
Organization.hasMany(models.accountBalance, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'accountBalances',
});
Organization.hasMany(models.serie, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'series',
});
Organization.hasMany(models.settingOrganization, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'settingOrganizations',
});
Organization.hasMany(models.setting, {
foreignKey: {
name: 'organizationIdKey',
field: 'organization_id',
},
as: 'settings',
});
};
return Organization;
};
Thanks,
Arne S.