Closed lolocr closed 5 years ago
@lolocr, there is no restriction of using LB4 relations with MSSQL connector. Do you have a sample app that can reproduce the problem? Thanks.
Yes! I have a repo here: https://github.com/lolocr/lb4auth I'm trying to create a 'hasMany' relation between 'RtvTransactions' and 'RtvTransArticles', where 'RtvTransactions' hasMany 'RtvTransArticles'. I have defined the relation in the model and the injections in the repository (TransactionRepository), but when I call the '/transactions' endpoint the console shows me the previous error. Thanks.
@lolocr , sorry about the late reply. Thanks for your sample repo. Since I don't have the right database schema, so I've tried to reproduce using in-memory database and it seems to be working fine. Before going into further, may I ask a trivial question: The error says Invalid column name 'RtvTransArticles'
. Do you actually have this column name in the specified table?
@dhmlau, thank you for reply. I don't have any column with this name. I need it? I have tried to use the the name of the column (transaction_id) in the relation, but the problem continues.
@lolocr , sorry about the late response. If you use the column name that actually exists, do you get another set of errors?
@dhmlau, finally I've been able to configure the relation between two models without errors. Now, when I try to include the relation in a query using the filter object, the framework shows this error: Relation "operatorGroup" is not defined in Operadores model
. I've found that the error is in loopback-datasource-juggler/lib/include.js
Can I use the 'include' filter value in my queries?
@lolocr, include
filter is not currently supported. Please see our spike in https://github.com/strongloop/loopback-next/pull/2124, and the original issue: https://github.com/strongloop/loopback-next/issues/1352.
If you agree, I'd like to continue the discussion in https://github.com/strongloop/loopback-next/issues/1352. Thanks.
Oks @dhmlau. Thanks.
I spent half of the day to find it out( it does not work.
Hello @JuliaRakitina,
What's your issue? I recommend you to update the loopback libraries to the latest version because solve some issues (hasMany relations for example). In my case, the problem was in the definition of the relation. I needed to declare de 'keyTo' value. In my case I had a User model hasMany UserVisibility (in this model had the property loginId, that is related to 'id' of the User model):
@hasMany(() => UserVisibility, {keyTo: 'loginId'}) userVisibilities?: UserVisibility[];
You can find more information here: https://github.com/strongloop/loopback-next/issues/1909
I hope it will help.
@lolocr no, I need filter include
currently using work around
I try to get data like below (Parent and child data).
[{ "_id" : 1, "name" : "testTeam", "todos" : [{ "id" : "1", "username" : "test user" }] }, { "_id" : 2, "name" : "testTeam", "todos" : [ { "id" : "2", "username" : "test user1" }] }]
But I Got the error "the relation is not defined for model loopback 4" when I use include filter option. Below code, I used in my application
@get('/todo-lists', { responses: { '200': { description: 'Array of TodoList model instances', content: { 'application/json': { schema: { 'x-ts-type': TodoList } } }, }, }, }) async find( ): Promise<TodoList[]> { return await this.todoListRepository.find({ include: [{ relation: 'todos' }] }); }
@AnanthGopal, we're currently on adding support for inclusion of related models. Please see this epic: https://github.com/strongloop/loopback-next/issues/1352. Thanks.
Hi @JuliaRakitina
You mentioned, "currently using workaround", Can you explain about that, I got the same issue. Now I am using the Stored procedure to resolve that issue.
Hi @AnanthGopal
Actually same :) I am using direct SQL query
I'm using loopback-connector-mssql with Loppback 4 version. When I have needed to use the relations with my models (belongsTo or Hasmany), I have the next error:
Exists any restriction to use the Loopback 4 relations with the mssql connector? Thank you in advance.