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

Foreign key objects in Nut::Row #116

Open
yusufmk opened this issue Oct 24, 2020 · 2 comments
Open

Foreign key objects in Nut::Row #116

yusufmk opened this issue Oct 24, 2020 · 2 comments

Comments

@yusufmk
Copy link

yusufmk commented Oct 24, 2020

Hi, I see that Nut::Row sharedpointers have fields related to their foreign keys. But they are always null. I want to be able to access those objects directly from the child table. Is this possible? Am I doing something wrong?

For example I have two tables, posts and comments:
"Comment" class has "Post" as foreign key. And "Post" class has "comments" as child table. Now, when I get a comment row with;
Nut::Row c = db.comments()->query()->first();

Here pointer "c" contains fields as postId and post. postId shows the related post's id. It is fine. BUT field "post" is always null. However it would be awesome if I could access to object post like this:
QString pn = c->post->postname(); // currently this line throws error, the app crashes, because c->post is nullptr.

I tried "join" but result is the same. post is always null.
Nut::Row c = db.comments()->query()->join()->first();
QString pn = c->post->postname(); // result is same as above.

Development platform:
OS: ubuntu 18.04
Qt creator 4.13.0, based on Qt 5.15.0
Compiler GCC 5.3.1
Nut commit hash: Commit 6ce50e2 by Jack Lilhammers, 07/07/2020 05:50 PM // this is the commit you used in OrmTest repo.
Serializer commit hash: Commit b0194da3 by Miklós Márton, 06/13/2020 12:00 AM // this is the commit you used in OrmTest repo.

Thank you in advance.

@HamedMasafi
Copy link
Owner

To join another table use template syntax; take a look at this text for example

auto q = db.posts()->query()

@yusufmk
Copy link
Author

yusufmk commented Oct 24, 2020

No no no, I already know this AND this is not what I want. This is showing accessing to "comment" FROM "post" object.
I want accessing to "post" FROM "comment" object.

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

No branches or pull requests

2 participants