Hi community,
I am again having issues with Types. However, now it is about relationship between objects.
I have created a table called Products that is linked to a Price, it is one by one relationship where price holds the relationship.
Here are the generated types:
export interface ApiProductProduct extends Schema.CollectionType {
collectionName: 'products';
info: {
singularName: 'product';
pluralName: 'products';
displayName: 'Products';
description: '';
};
options: {
draftAndPublish: false;
};
pluginOptions: {
i18n: {
localized: true;
};
};
attributes: {
name: Attribute.String &
Attribute.Required &
Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
active: Attribute.Boolean &
Attribute.SetPluginOptions<{
i18n: {
localized: false;
};
}> &
Attribute.DefaultTo<true>;
description: Attribute.Text &
Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
id_stripe: Attribute.String &
Attribute.SetPluginOptions<{
i18n: {
localized: false;
};
}>;
url: Attribute.String &
Attribute.SetPluginOptions<{
i18n: {
localized: false;
};
}>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'api::product.product',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'api::product.product',
'oneToOne',
'admin::user'
> &
Attribute.Private;
localizations: Attribute.Relation<
'api::product.product',
'oneToMany',
'api::product.product'
>;
locale: Attribute.String;
};
}
export interface ApiProductsPriceProductsPrice extends Schema.CollectionType {
collectionName: 'products_prices';
info: {
singularName: 'products-price';
pluralName: 'products-prices';
displayName: 'Products Prices';
description: '';
};
options: {
draftAndPublish: false;
};
attributes: {
currency: Attribute.Enumeration<['eur', 'usd', 'brl']> &
Attribute.Required &
Attribute.DefaultTo<'eur'>;
active: Attribute.Boolean & Attribute.Required & Attribute.DefaultTo<true>;
amount: Attribute.Decimal &
Attribute.Required &
Attribute.SetMinMax<
{
min: 0;
},
number
>;
id_stripe: Attribute.String;
product: Attribute.Relation<
'api::products-price.products-price',
'oneToOne',
'api::product.product'
>;
usage_type: Attribute.Enumeration<['licensed', 'metered']> &
Attribute.DefaultTo<'licensed'>;
interval: Attribute.Enumeration<['day', 'week', 'month', 'year']>;
interval_count: Attribute.Integer &
Attribute.SetMinMax<
{
min: 1;
},
number
>;
billing_scheme: Attribute.Enumeration<['per_unit', 'tiered']> &
Attribute.Required &
Attribute.DefaultTo<'per_unit'>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'api::products-price.products-price',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'api::products-price.products-price',
'oneToOne',
'admin::user'
> &
Attribute.Private;
};
}
Then I am exporting it like this to use in my code:
import type { Attribute } from '@strapi/strapi';
export type StrapiProduct = Attribute.GetValues<"api::product.product">;
export type StrapiProductsPrice = Attribute.GetValues<"api::products-price.products-price">;
However, when running the code, I am getting another object from the Product instead StrapiProduct as declared before.
Here is what I am getting:
{
disconnect: [
],
connect: [
{
id: 13,
position: {
end: true,
},
},
],
}
I would like to know, how can I read using a price.product.id or even a price.product[0].id?
Has this not been implemented yet? Is this a bug? Am I missing something silly?
Any help is appreciated! Thanks in advance
Best regards,
Marlos Damasceno
System Information
- Strapi Version: 4.25.1
- Operating System: Windows 11 (running WSL2 (5.15.133.1-microsoft-standard-WSL2) with Ubuntu 22.04.3 LTS)
- Database: MySQL
- Node Version: 18.20.2
- NPM Version: -
- Yarn Version: 1.22.19