0

In my flutter project i m doing offline module using objectBox database.In this module i have three tables ItemMaster table,customerMaster table and customerWiseStock table. I have the data of itemMaster and customerMaster tables and i want to get stock it depends on itemId(ItemMaster) and salestypeId(CustomerMaster).

How to do anyone help?

here i have attach the picture for refrence. enter image description here

vaind
  • 1,642
  • 10
  • 19
Kalp Shah
  • 279
  • 2
  • 14
  • 1
    It's not clear what the question is. To get the data filtered by any column, use queries. If that doesn't help maybe you can try to rephrase the question , ideally with some code – vaind Jul 20 '21 at 06:57
  • 1
    @vaind Thanks for your reply, The main question is I want to join 2 tables with the `salesTypeId` column (in both tables) and get all the fields from the first table as well as one column from the second table. – Pratik Butani Jul 20 '21 at 08:12

2 Answers2

1

First, it's important to acknowledge that ObjectBox is not relational DB and that one cannot always apply relational mechanisms.

Here's how you would typically approach this using ObjectBox:

  1. Define relations between your entities (you don't need to model ID properties)
  2. Define your query for the main result type and use links to "join" the other types in the query
  3. From the result objects, you traverse the relations from a "main type" object to get the other types and thus to any property.

Note: ObjectBox is extremely fast when it comes to creating objects. So traversing related objects is usually a no-issue, especially when done in a transaction.

Markus Junginger
  • 6,950
  • 31
  • 52
0

Mixing up "columns" from separate "tables" is not something you can do with ObjectBox. It is statically typed (and withs static schema), meaning the Dart objects are mapped directly to the data stored in the database. What you're describing is something you'd expect from an SQL database, with dynamic results (Dart type could be something like List<Map<String, dynamic>>).

If you want to use an object database (not limited to ObjectBox), I suggest you think about de-normalizing your data where it makes sense. With ObjectBox relations (links) you should be able to achieve the same, but with fewer classes and still in a type-safe manner.

If you have some concrete Dart code (classes for the "entities") and an the data you want to query, I may be able to provide suggestion on how to clean things up.

vaind
  • 1,642
  • 10
  • 19
  • 1
    So ObjectBox is not providing that type of join query where we can combine the two table's data? I think its biggest drawbacks is that we can do simple joins to get (filtered) data from one table but not from **more than one tables.** – Pratik Butani Jul 21 '21 at 06:15
  • Btw, we had some ideas on how to tackle allow that, but interest was not high enough to actually implement this just yet... Most people seem to be fine without. – Markus Junginger Jul 21 '21 at 18:03