GithubHelp home page GithubHelp logo

Comments (20)

DesmondFox avatar DesmondFox commented on June 22, 2024 5

Any updates?

from floor.

JoeSteven avatar JoeSteven commented on June 22, 2024 5

Any updates?

from floor.

vitusortner avatar vitusortner commented on June 22, 2024 3

This is planned for a future release of the library. Unluckily, I can't tell when it's going to be.

from floor.

ForceTower avatar ForceTower commented on June 22, 2024 2

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:
https://gist.github.com/ForceTower/1d9acd12e772fe352bedcd5e640de7e2

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.

from floor.

proninyaroslav avatar proninyaroslav commented on June 22, 2024 2

@ForceTower
Android Room uses Observable to listen selected tables. I think we can use FloorDatabase.changeListener for this purpose.

from floor.

mt-akar avatar mt-akar commented on June 22, 2024 1

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.

from floor.

pishguy avatar pishguy commented on June 22, 2024

the library can be support relation ship?

from floor.

hsul4n avatar hsul4n commented on June 22, 2024

Any updates @vitusortner

from floor.

locskot avatar locskot commented on June 22, 2024

Hi there!
Is there any support to one-to-many relation? How can i get stored in db complex object (not just simple strings and ints but also list)?

from floor.

proninyaroslav avatar proninyaroslav commented on June 22, 2024

@ForceTower
This is not a complete implementation. Here you only listen Article table (one stream), and after changing Article, you grab the data from AuthorArticleId. But what if the data in AuthorArticleId is mutable, and you need to listen changes from Article and AuthorArticleId at the same time (equivalent to listening two streams)?

from floor.

ForceTower avatar ForceTower commented on June 22, 2024

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

from floor.

BrianMwas avatar BrianMwas commented on June 22, 2024

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:
https://gist.github.com/ForceTower/1d9acd12e772fe352bedcd5e640de7e2

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.

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.
Any help would be amazing

from floor.

ForceTower avatar ForceTower commented on June 22, 2024

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.
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 pointed out in this example

from floor.

BrianMwas avatar BrianMwas commented on June 22, 2024

from floor.

Velkamhell97 avatar Velkamhell97 commented on June 22, 2024

Any updates ?

from floor.

taosif7-dreamorbit avatar taosif7-dreamorbit commented on June 22, 2024

Any Updates?

from floor.

Artem-S1 avatar Artem-S1 commented on June 22, 2024

Any updates?

from floor.

juanes30 avatar juanes30 commented on June 22, 2024

Any updates?

from floor.

ngminhkhoa avatar ngminhkhoa commented on June 22, 2024

Any updates ?

from floor.

adlerbn avatar adlerbn commented on June 22, 2024

Any updates ?

from floor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.