-
Notifications
You must be signed in to change notification settings - Fork 193
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
Support relations with @Relation annotation #47
Comments
the library can be support relation ship? |
This is planned for a future release of the library. Unluckily, I can't tell when it's going to be. |
Any updates @vitusortner |
Hi there! |
If you guys ever used Room (the library this is based), and checked out the generated code, you may write the boilerplate yourself and get the relations. In my case I have the entities Article, Author and ArticleAuthor (that assigns a article to an author). I started playing with flutter/dart this week, so you might see some improvements in the code: In this case, AuthorArticleId is a DatabaseView, since this library at this time doesn't support @Embedded or map the database query to any model class. The query code of the DatabaseView can be anything, it just exists so the code generator knows how to map the query result to the model I want. The line https://gist.github.com/ForceTower/1d9acd12e772fe352bedcd5e640de7e2#file-article_dao-dart-L15 is horrible, Room fetches the results and places them into a HashMap based on the pivot table id (in my case, articleId) to increase performance, since findWhere is a O(N) and there might be a lot of models to go through. |
@ForceTower |
@proninyaroslav The implementation I shared does indeed has a flaw, if the author itself changes, the changes of it are not propagated into the stream. I believe the desired behavior would be achievable by listening to a second stream (of authors) and publishing snapshots of both in the result stream. But that seems like a code smell :( Or maybe to create and dependency on the first query to both tables, this way one single stream would do the job correctly. |
@ForceTower |
Hi @ForceTower I saw the SQL statement used supports one to one relationship how would I manage a one to many kind of relationship. In this case, you have an author with many articles. I would as a result get a List of authors with lists of articles for each of them. |
Hey there, in the example I shared, I believe the tables were set up to a N..N relationship, So... lets assume you have a proper 1..N relation, like a movie and it's posters :D
If I remember correctly to implement a 1..N room does something like: The secret behind the N..N relationship is the line https://gist.github.com/ForceTower/1d9acd12e772fe352bedcd5e640de7e2#file-article_dao-dart-L15 there I did a But... Be aware of the error @proninyaroslav pointed out in this example |
Thanks alot man will consider the error
…On Fri, 9 Jul 2021, 2:38 pm João Sena, ***@***.***> wrote:
Hi @ForceTower <https://github.com/ForceTower> I saw the SQL statement
used supports one to one relationship how would I manage a one to many kind
of relationship. In this case, you have an author with many articles. I
would as a result get a List of authors with lists of articles for each of
them.
Any help would be amazing
Hey there, in the example I shared, I believe the tables were set up to a
N..N relationship, So... lets assume you have a proper 1..N relation, like
a movie and it's posters :D
class MoviePoster {
final int id;
final String image;
final int movieId;
MoviePoster(this.id, this.image, this.movieId);
}
If I remember correctly to implement a 1..N room does something like:
1 - Fetch the movies
2 - Map the movie list where for each movie, you select from poster table
based on the movie id (this will give you a list of posters) and create an
object with the movie and the posters list.
3 - Return the mapped list
The secret behind the N..N relationship is the line
https://gist.github.com/ForceTower/1d9acd12e772fe352bedcd5e640de7e2#file-article_dao-dart-L15
there I did a firstWhere which returns a single author, if you just do a
where , you'd have a List<Author> for an Article.
To do what you asked basically invert the 2 tables used in the example.
But... Be aware of the error @proninyaroslav
<https://github.com/proninyaroslav> pointed out in this example
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKHG7KFZAMLNFMNNCFHI4PLTW3NSPANCNFSM4GXDOEEA>
.
|
Any updates on the @relation? It makes data retrieval so much easier. This is very important to me. I will settle with the first decent ORM I find that supports this feature. |
Any updates? |
1 similar comment
Any updates? |
Any updates ? |
Any Updates? |
Any updates? |
Any updates? |
Any updates ? |
1 similar comment
Any updates ? |
No description provided.
The text was updated successfully, but these errors were encountered: