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

ORM select query not working both ways #36

Closed
jkemming opened this issue Apr 24, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@jkemming
Copy link

commented Apr 24, 2018

I have an application with two tables named videos and producers respectively. The models are as follows:

nSQL('videos')
  .model([
    { key: 'id', type: 'int', props: ['pk', 'ai'] },
    { key: 'name', type: 'string' },
    { key: 'producerId', type: 'producers', props: ['ref=>videoIds[]'] }
  ]);
nSQL('producers')
  .model([
    { key: 'id', type: 'int', props: ['pk', 'ai'] },
    { key: 'name', type: 'string' },
    { key: 'videoIds', type: 'videos[]', props: ['ref=>producerId'] }
  ]);

It is a one-to-many relationship, that means each producer has many videos and each video has one producer. Inserting entries works like a charm, my test data looks as follows inside IndexedDB:

videos Table:

Key Value
1 { id: 1, name: "test1", producerId: 1 }
2 { id: 2, name: "test2", producerId: 1 }
3 { id: 3, name: "test3", producerId: 2 }

producers Table:

Key Value
1 { id: 1, name: "prod1", videoIds: [1, 2] }
2 { id: 2, name: "prod2", videoIds: [3] }

Now I want to request an entry from the videos table with its respective producer in the result as follows:

nSQL('videos')
  .query('select')
  .orm(['producerId'])
  .where(['id', '=', 1])
  .exec();

The result however looks like this:

{
  id: 1,
  name: "test1",
  producerId: 1
}

If I try it the other way around it does work:

nSQL('producers')
  .query('select')
  .orm([videoIds'])
  .where(['id', '=', '1'])
  .exec();

The result is:

{
  id: 1,
  name: "prod1",
  videoIds: [
    { id: 1, name: "test1", producerId: 1 },
    { id: 2, name: "test2", producerId: 2 }
  ]
}

I already tried and tested a lot on my end but can't seem to find a bug in my application. Also, I copied and ran the example from the official documentation which gave the same results, meaning the author variable in that case was still the user id rather than the user object.

Am I doing something wrong or is there possibly a bug?

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Apr 24, 2018

Just pushed v1.5.2, issue should be resolved.

Thanks for the heads up!

@jkemming

This comment has been minimized.

Copy link
Author

commented Apr 25, 2018

Thank you very much for the quick fix, now everything is working as it's supposed to be!

@jkemming jkemming closed this Apr 25, 2018

@ClickSimply ClickSimply added the bug label Apr 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.