0

I have this ToMany relation:

@Entity()
class Cikkek {
  @Id()
  int id;
  int cikkid = 0;
  String cikkszam = '';

  @Backlink("cikk")
  final Vkodok = ToMany<Vonalkodok>();

  Cikkek(this.id, this.cikkid, this.cikkszam);
}

@Entity()
class Vonalkodok {
  @Id()
  int id;
  int cikkid = 0;
  String azonosito = "";

  Vonalkodok(this.id, this.cikkid, this.azonosito);

  final cikk = ToOne<Cikkek>();
}

When I build it with flutter pub run build_runner build, I get Cannot use the default constructor of 'Vonalkodok': don't know how to initialize param cikkid - no such property..

What is the problem here? Because I clearly give cikkid a value in my constructor.

UPDATE:

I noticed, if I comment out the final cikk = ToOne<Cikkek>(); row, it is building.

Now I renamed the ToOne relation from cikk to termek, and now it seems ok.

Checking the generated objectbox-model.json, I think I understand why I got into this problem. In this json the termek ToOne field generated with a "name": "termekId",. So with cikk it would generate to cikkid, which is the same as my int field.

This could cause the error.

I think this is an objectbox limitation. I don't know if it is documented or not?

Ebadta
  • 317
  • 1
  • 3
  • 10
  • If I comment out the ```final cikk = ToOne();``` row, it is ok, but in the documentation example, they have the ToOne relation too. – Ebadta Feb 12 '23 at 17:10

0 Answers0