-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extended repository example in document is not working #6139
Comments
@adrien2p can I get you to confirm if this solution is correct? |
@shahednasser @vinhnguyen1211 yes it seems that the documentation is missing the target replacement. it should be something like export const ProductRepository = dataSource
.getRepository(Product)
.extend({
// it is important to spread the existing repository here.
// Otherwise you will end up losing core properties
...Object.assign(MedusaProductRepository, { target: Product })
/**
* Here you can create your custom function
* For example
*/
customFunction(): void {
// TODO add custom implementation
return
},
}) |
@adrien2p @shahednasser spread operator doesn't work. I just test with your code snippet, it should be like this export const OrderRepository = dataSource.getRepository(Order).extend(
Object.assign(MedusaOrderRepository, {
customFunction(): void {
// TODO add custom implementation
return
}
}),
); seems |
Have you tried fetching orders at http://localhost:9000/admin/orders? When I use spread operator I got that error again, I also extend Order service class OrderService extends MedusaOrderService {
static LIFE_TIME = Lifetime.SCOPED;
protected readonly loggedInUser_: User | null;
constructor(container, options) {
// @ts-expect-error prefer-rest-params
super(...arguments);
try {
this.loggedInUser_ = container.loggedInUser;
} catch (e) {
// avoid errors when backend first runs
}
}
async listAndCount(
selector: QuerySelector<Order> & { store_id?: string },
config?: FindConfig<Order>,
): Promise<[Order[], number]> {
if (!selector.store_id && this.loggedInUser_?.store_id) {
selector.store_id = this.loggedInUser_.store_id;
}
if (config?.select?.length) {
config.select.push('store_id');
}
if (config?.relations?.length) {
config.relations.push('store');
}
return super.listAndCount(selector, config);
}
} |
would you mind also extending OrderService, the important is |
sure, give me a sec |
Thanks. So I got there're weird issues from my end. |
- Issue ticket #6139 - Update document how to extend repository
I recently updated from medusajs/medusa 1.17.2 to medusajs/medusa 1.20.0, and i have the same problem in 1.20.0 where spread operator does not work (it was working in 1.17.2). The suggestion @shahednasser provided seems to fix the problem
|
Same here as @corentinbranchereau . I updated from old version to 1.20.0, and re-installed node modules. |
Facing the same issue. Spread operator breaks the functionality. Unfortunately I depend on it in one case, so it broke admin categories completely. |
Facing the same issue. Spread operator is not working only in the case of Extending Product Entity as in the example.
|
I am having the exact same issue with version 1.20.7 |
v1.20.8 +
|
Preliminary Checks
Issue Summary
I'm following this guide https://docs.medusajs.com/development/entities/extend-repository#step-2-implement-extended-repository
When I call http://localhost:9000/admin/products it keeps saying
productRepo.findWithRelationsAndCount is not a function
How can this issue be resolved?
I was able to fix the issue by proper deep copy
Are you interested in working on this issue?
The text was updated successfully, but these errors were encountered: