Jaguar-dart / jaguar_orm

Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
https://jaguar-dart.github.io
BSD 3-Clause "New" or "Revised" License
217 stars 52 forks source link

ForeignKey question #110

Closed carmas123 closed 5 years ago

carmas123 commented 5 years ago

I'm a Kotlin developer and came from Android to Flutter and in Android I use DBFlow a very powerful Android ORM. In DBFlow I've the class of model and I can add the foreignkey very simple with a column type of linked class. For example:

class MyTable {
  @PrimaryKey
  var id: Int;
  var description: String;
  @ForeignKey(...FOREIGN KEY ATTRIBUTES...)
  var linkedValue: MyLinkedTable;
}

class MyLinkedTable {
  @PrimaryKey
  var id: Int;
  var value: String;
}

with this method I can access to MyLinkedTable using the MyTable.linkedValue field, like this.

MyTable.linkedValue.value

accessing to linked table value is very simple.

How can I do some like this with JaguarORM?

tejainece commented 5 years ago

@carmas123 Thanks for the question. In Jaguar, one has to generate beans to generate the ORM logic for the given model. There is one bean for every model in the database.

For one-to-one relationship, please refer this wiki post: https://github.com/Jaguar-dart/jaguar_orm/wiki/One-to-one-relationship

There is a one-to-one example here: https://github.com/Jaguar-dart/jaguar_orm/blob/master/orm/example/model/associations/one_to_one/simple.dart

Basically, you are looking for annotations: HasOne and BelongsTo.

carmas123 commented 5 years ago

Yes I try it.... But I don't understand why I need to add references into mi parent table "BelongsTo"... and I got an error whan I try to use this methods in generation.

tejainece commented 5 years ago

Thanks for quick reply. Do you have gitter?

tejainece commented 5 years ago

You can chat with us here: https://gitter.im/jaguar_dart/jaguar

carmas123 commented 5 years ago

Yes I talk now