floor icon indicating copy to clipboard operation
floor copied to clipboard

Relationship with entities and queries

Open afiocre opened this issue 4 years ago • 4 comments

Hi,

is it possible to do into the DAO a join with 2 entities who are link with foreign key ? In order to have the parent and a list of children into the parent object ?

And if we have always the parent and a list of children in memories, can we use the @insert in order to insert into Moor on the 2 tables (like cascade in Doctrine) ?

If yes, do you have example of this 2 questions ?

Thanks

afiocre avatar Jan 13 '21 17:01 afiocre

is it possible to do into the DAO a join with 2 entities who are link with foreign key ? In order to have the parent and a list of children into the parent object ?

Joined return values (e.g. parent with children in one row) are currently only partly supported. Can a database view help you in this situation? Database views fully support JOIN clauses.

And if we have always the parent and a list of children in memories, can we use the @insert in order to insert into Moor on the 2 tables (like cascade in Doctrine) ?

If both floor and moor databases access the same database file, there should technically not be a problem with that. I have never tried that myself though.

vitusortner avatar Feb 13 '21 17:02 vitusortner

This feature would be amazing, I’m actually currently working on it. Similar to what django offers.

idkq avatar Feb 14 '21 16:02 idkq

Take a look https://github.com/vitusortner/floor/discussions/492

idkq avatar Feb 15 '21 01:02 idkq

Joins as a feature can be achieved through multiple means:

  • through @Relation (#47)
  • through returning arbitrary objects in @Querys (#94)
  • through assembling views for the returned objects (already implemented, see https://vitusortner.github.io/floor/database-views/.)

But as this question isn't asked for the first time, I think we should improve the documentation on views, to include at least an example for joins.

mqus avatar Apr 23 '21 15:04 mqus