objectbox / objectbox/objectbox-dart
Create relationships automatically from class without needing to define one
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 1.2k
- Forks
- 162
- Avg merge
- 15m
- Merged PRs (30d)
- 1
Description
Describe the solution you'd like
When the class (object) is defined everything within the object has data types. It would be great if relationships could get generated from types instead of needing to define one. When a call is made to retrieve data from an objectbox put appropriate relationship objects in those. This is something like Entity Framework in .NET. I will use an example from my app. In this example, this is how my object comes from the server (JSON).
class WorkoutAssignment {
int id;
String userId;
Workout workout;
}
class Workout [ // Child of WorkoutAssignment
int id;
int workoutAssignmentId;
int name;
List<Interval> intervals;
}
class Interval { // Child of Workout
int id;
int workoutId;
int duration;
int rest;
}
When an object comes in, I cannot simply put it in the database and I cannot use the same variable names like this
// In case of WorkoutAssignment
final ToOne<Workout> workout = ToOne<Workout>();
// In case of Workout
@Backlink()
final ToMany<Interval> intervals = ToMany<Interval>();
final ToOne<WorkoutAssignment> wa = ToOne<WorkoutAssignment>();
// In case of Interval
final ToOne<Workout> workout = ToOne<Workout>();
Describe alternatives you've considered
Currently, I am using a separate class that will handle objectbox and creates mappings for those. This can be time-consuming as more classes are generated and it easily leads to errors.
I could use existing classes and create relationships with different variable names but that would just lead to confusion about which variable to use where and creates additional "what-if" cases
Additional context
I believe that many developers could benefit from automatic object relationship creation as it would lead to fewer errors and a lot of time-saving. I am more than happy to contribute to the plugin although I am not an expert on data structures, thus I cannot comment on this being easy or hard, but I would help in any way I can.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by reviewing how ObjectBox Dart currently defines ToOne and ToMany relationships and how generated models handle them. Compare that behavior with the WorkoutAssignment, Workout, and Interval examples; done would require an agreed design and tests covering automatic relationship creation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100