var legendItem = orm.populate(orm.new(“KmlLayerLegendItem”),item);
layer.addLegendItem(legendItem);
legendItem.save();
}
layer.save();
`
I have an entity KmlLayer, with a one to many association KmlLayerLegendItem.
The above code is creating a new LegendItem, and saving it to a KmlLayer. The LegendItem is creating and saving to the DB fine, but the foreign key (layer_id) in the LegendItemt is not getting populated… so the LegendItem is saving to the DB, but not associated with the Layer that I add() it to.
I have a feeling it has to do with the order I am saving the layer and legendItem, but from what I can tell reading docs, what I have should be fine.
Correct me, but layer already exists and has been persisted, then your running this is that right? I think in this case, as you’re adding them to the layer as children. I think ORM wants / needs you to save the layer and not the items.
Correct, the parent object (layer) already exists, and I am getting it with var layer = orm.get(“KmlLayer”,rc.id);… I then want to add children to it.
I’ve tried saving the parent object as well… tried all sorts of combinations but just can’t get it to save with the FK…
It’s tedious alright… I’ve got this working plenty of times before, but just doesn’t want ot play this time… Unfortunately might need to give up and go back to a good old fashion query.