-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Retrieval of related model for a HasMany
relation
#1372
Comments
It corresponds to the first 2 points from #1032 (comment):
|
Here is what I have in mind: export class CustomerRepository {
// We should be able to inject a factory of OrderRepository by name or instance
// and infer `Order` from the `OrderRepository`
@hasMany('orderRepository'); // The argument can be an object to pass in more info
public readonly orders: (key: Partial<Customer>) => OrderRepository;
} async function getCustomerOrders(customerId: number): Promise<Order[]> {
return await customerRepo.orders({id: customerId}).find();
} |
@b-admike a question for the code snippet: export class CustomerController {
constructor(
@repository(CustomerRepository) protected customerRepo: CustomerRepository,
@repository(OrderRepository) protected orderRepo: OrderRepository
) {}
async function getCustomerOrders(customerId: number): Promise<Order[]> {
return await customerRepo.orders.find(customerId, orderRepo);
}
async function createCustomerOrders(customerId: number, orderData: Partial<Order>): Promise<Order> {
return await customerRepo.orders.create(customerId, orderData, orderRepo);
}
} Does it mean we automatically get the related property
|
@jannyHou yeah that's correct. |
See also #1353 |
Closing as #1438 has landed. |
Description
Follow up for #1342. Given
Customer
andOrder
models, and a customer that has orders already, I would like to define aHasMany
relation andAcceptance Criteria
hasMany
decorator to construct constrained target repository instance on relational propertycustomerRepo.<decorated_property_name or relation_name>.update(...)
) using the relation metadata and supplied constraint in the controller methodCode snippet for UX:
See Reporting Issues for more tips on writing good issues
The text was updated successfully, but these errors were encountered: