Skip to content
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

Loopback 4 relations compatibility #194

Closed
lolocr opened this issue Oct 18, 2018 · 15 comments
Closed

Loopback 4 relations compatibility #194

lolocr opened this issue Oct 18, 2018 · 15 comments
Assignees

Comments

@lolocr
Copy link

lolocr commented Oct 18, 2018

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:

Unhandled error in GET /transactions-articles: 500 RequestError: Invalid column name 'RtvTransArticles'.
    at handleError (/Library/WebServer/Documents/rtv-node/node_modules/mssql/lib/tedious.js:546:15)
    at Connection.emit (events.js:182:13)
    at Parser.<anonymous> (/Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/connection.js:611:16)
    at Parser.emit (events.js:182:13)
    at Parser.<anonymous> (/Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/token-stream-parser.js:54:15)
    at Parser.emit (events.js:182:13)
    at addChunk (/Library/WebServer/Documents/rtv-node/node_modules/readable-stream/lib/_stream_readable.js:291:12)
    at readableAddChunk (/Library/WebServer/Documents/rtv-node/node_modules/readable-stream/lib/_stream_readable.js:278:11)
    at Parser.Readable.push (/Library/WebServer/Documents/rtv-node/node_modules/readable-stream/lib/_stream_readable.js:245:10)
    at Parser.Transform.push (/Library/WebServer/Documents/rtv-node/node_modules/readable-stream/lib/_stream_transform.js:148:32)
    at doneParsing (/Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/stream-parser.js:110:18)
    at /Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/infoerror-token-parser.js:46:5
    at /Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/infoerror-token-parser.js:13:19
    at /Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/stream-parser.js:247:9
    at Parser.awaitData (/Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/stream-parser.js:144:9)
    at Parser.readUInt32LE (/Library/WebServer/Documents/rtv-node/node_modules/tedious/lib/token/stream-parser.js:244:12)

Exists any restriction to use the Loopback 4 relations with the mssql connector?
Thank you in advance.

@dhmlau
Copy link
Member

dhmlau commented Oct 18, 2018

@lolocr, there is no restriction of using LB4 relations with MSSQL connector. Do you have a sample app that can reproduce the problem? Thanks.

@dhmlau dhmlau self-assigned this Oct 18, 2018
@lolocr
Copy link
Author

lolocr commented Oct 19, 2018

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.

@dhmlau
Copy link
Member

dhmlau commented Oct 25, 2018

@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?

@lolocr
Copy link
Author

lolocr commented Oct 25, 2018

@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.

@dhmlau
Copy link
Member

dhmlau commented Nov 10, 2018

@lolocr , sorry about the late response. If you use the column name that actually exists, do you get another set of errors?

@lolocr
Copy link
Author

lolocr commented Dec 20, 2018

@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?

@dhmlau
Copy link
Member

dhmlau commented Jan 14, 2019

@lolocr, include filter is not currently supported. Please see our spike in loopbackio/loopback-next#2124, and the original issue: loopbackio/loopback-next#1352.

If you agree, I'd like to continue the discussion in loopbackio/loopback-next#1352. Thanks.

@lolocr
Copy link
Author

lolocr commented Jan 14, 2019

Oks @dhmlau.
Thanks.

@lolocr lolocr closed this as completed Jan 14, 2019
@JuliaRakitina
Copy link

JuliaRakitina commented Jan 18, 2019

I spent half of the day to find it out( it does not work.

@lolocr
Copy link
Author

lolocr commented Jan 19, 2019

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.

@JuliaRakitina
Copy link

JuliaRakitina commented Jan 20, 2019

@lolocr no, I need filter include

currently using work around

@AnanthGopal
Copy link

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' }] }); }

@dhmlau
Copy link
Member

dhmlau commented Apr 17, 2019

@AnanthGopal, we're currently on adding support for inclusion of related models. Please see this epic: loopbackio/loopback-next#1352. Thanks.

@AnanthGopal
Copy link

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.

@JuliaRakitina
Copy link

Hi @AnanthGopal

Actually same :) I am using direct SQL query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants