Comments (20)
Any updates?
from floor.
Any updates?
from floor.
This is planned for a future release of the library. Unluckily, I can't tell when it's going to be.
from floor.
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.
@ForceTower
Android Room uses Observable
to listen selected tables. I think we can use FloorDatabase.changeListener for this purpose.
from floor.
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.
the library can be support relation ship?
from floor.
Any updates @vitusortner
from floor.
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.
@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.
@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.
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/1d9acd12e772fe352bedcd5e640de7e2In 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.
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.
from floor.
Any updates ?
from floor.
Any Updates?
from floor.
Any updates?
from floor.
Any updates?
from floor.
Any updates ?
from floor.
Any updates ?
from floor.
Related Issues (20)
- Improve FTS documentation and add some examples
- Not supported on Flutter Web HOT 1
- dependecy conflict with riverpod_lint 2.3.3 HOT 2
- Dumplicate field name when entity implement form abstract class HOT 1
- duplicate field name when entity implement form abstract class
- Unhandled Exception: type 'Null' is not a subtype of type 'double' in type cast HOT 1
- This exception cannot be executed on the entire floor library
- trying to get a SUM of a field with floor. HOT 1
- Custom Database File Path
- sqlite wal HOT 1
- How to update a List of an object as field of entity into table in Floor
- How add rawQuery added ?? HOT 2
- Are there any plans to adapt HarmonyOS HOT 4
- Imports collision HOT 1
- #802 still an issue. any help?
- Casting to double might not work; HOT 1
- dependencies issue HOT 5
- Invalid query (failing to parse) does not throw an error
- onCreate callback is not being called, "tbl not found" exception
- How to select with like ??? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from floor.