In a table, I have 2 columns which are foreign keys to same table, and generated schema create error at runtime :
warning: Skipping relation “partner.partners_through_partner_contract_templates” because of error: You have used the alias partners_through_partner_contract_templates in two separate associations. Aliased associations must have unique aliases.
CREATE TABLE IF NOT EXISTS public.partner
(
id BIGSERIAL NOT NULL,
external_id TEXT NOT NULL,
code text NOT NULL,
label text NOT NULL,
customer_service_email TEXT,
);
CREATE TABLE IF NOT EXISTS public.partner_contract_templates (
warranty_partner_id BIGINT NOT NULL,
lender_partner_id BIGINT NOT NULL,
pledge_template_res_path TEXT
);
But it seems the alias is generated in .forestadmin.schema.json…I don’t know how to customise this.
Could you please share the relations you have defined on your partner_contract_templates table ?
My first guess is that the constraints you have defined to the partner table have duplicated names which causes errors on introspection.
I tried to replicate your setup via the queries you provided, I have no issue making it work with the createSqlDataSource, on which version of this package do you experience this issue ?
I am also wondering why and how you are using 2 different dataSources
I still cannot reproduce with datasource-sql: ^1.7.39
Let’s try to single out the datasource causing this issue in your configuration, could you please start the agent with one datasource at a time ?
I am sorry if It was not clear, I am suggesting you to start your agent on your development environment with only one datasource at a time to check which one logs the warning Skipping relation “partner.partners_through_partner_contract_templates”. This is only temporary so as to not investigate on the wrong datasource.
As the sqlDataSource does the introspection on its own and the sequelizeDataSource works based on the sequelize instance with loaded models (and their configuration) that you pass as parameter.
If you are unable to start your agent with only one datasource because of customizations that require collections from both datasources, we can simply check any customizations or models defined for your table partner_contract_templates
I have removed collection customization to be able to run it…Problem does not occurs If I use createSequelizeDataSource, but it still remains if I use createSqlDataSource.
Thanks for the additional information.
Sadly I still couldn’t reproduce the issue, if you are comfortable with it, could you please send me a backup of your database only containing the structure, no data, via private message.
CREATE TABLE IF NOT EXISTS public.partner
(
id BIGSERIAL NOT NULL,
external_id TEXT NOT NULL,
code text NOT NULL,
label text NOT NULL,
);
CREATE TABLE IF NOT EXISTS public.partner_contract_templates (
warranty_partner_id BIGINT NOT NULL,
lender_partner_id BIGINT NOT NULL,
);
CREATE TABLE IF NOT EXISTS public.acceptable_lender_warranty_partnership (
warranty_partner_id BIGINT NOT NULL,
lender_partner_id BIGINT NOT NULL
);
public.partner_contract_templates and public.acceptable_lender_warranty_partnership have foreign keys to partner table with same field name. This was causing trouble when Sequelize generate reverse relation.
I have renamed fields like below and it works fine now :
CREATE TABLE IF NOT EXISTS public.acceptable_lender_warranty_partnership (
acceptable_warranty_partner_id BIGINT NOT NULL,
acceptable_lender_partner_id BIGINT NOT NULL
);