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

Many to many cascate flag #103

Closed hjJunior closed 5 years ago

hjJunior commented 5 years ago

This issue is from the same bean of #98, So I've OrderBean and Products where is connected by OrderItemBean

So looking for insert and update methods on generate file, I was thinking about cascate flag, what do u think about it, some ORM you can setup to create only the relation (pivot table). At Jaguar ORM the cascate method try to insert Product and OrderItem

for (final child in model.orderItems) {
  await productBean.insert(child, cascade: cascade);
  await orderItemBean.attach(child, model);
}

So I'd like to work on it, maybe a new flag and on this loop check if product already exist and avoid to create it

Or maybe, I just need to create a new relation hasMany between Order and OrderItem

hjJunior commented 5 years ago

I solved this problem using upsert istead of insert