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

Manage association with object and not foreign key #147

Open jaumard opened 5 years ago

jaumard commented 5 years ago

I always find it weird that for one-to-many we set List<Object> in one side and only int id on the other side,

As v4 is going on I propose to change to always manage association with object instead of foreign key.

The will also us to use preload to load directly the nested object.

Most ORM manage relations with objects, I think it will be better to do it.

What do you think ?

tejainece commented 5 years ago

Can you give an example?

On parent side it is object. On child side, it is foreign key.

If you mean jaguar should create the foreign keys for the user instead?

jaumard commented 5 years ago

That's exactly that, in some case you might want to define your own foreign key but in most cases you're interested in getting the related parent. That can be a nice addition :)

JankoLancer commented 5 years ago

That would be perfect addition.

HTMHell commented 5 years ago

@jaumard any idea when this will be available?

jaumard commented 5 years ago

No idea, I don't think someone is working on this so I'll say not any time soon. But PR are welcome if you're motivated to do it