AnantLabs / codesmith

Automatically exported from code.google.com/p/codesmith
1 stars 0 forks source link

CSLA: Not inserting Switchable Grandchild objects #665

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When you must insert a Child with its Grandchild, and the grandchild is a 
switchable object, the grandchild are not inserted.

Not happening on Update, only when inserting the grandchild.

I had a look to the tamplates and I think that I discovered the cause (on the 
VB templates).

On ChildUpdate.ParametrizedSQL.cst we can see the following lines:

        For Each a As IAssociation In Entity.Associations.Where(Function(assoc) assoc.AssociationType = AssociationType.OneToMany OrElse assoc.AssociationType = AssociationType.ZeroOrOneToMany OrElse assoc.AssociationType = AssociationType.ManyToMany)
             If IsChildBusinessObject(a) Or IsSwitchableObject(a) Then
                 childCount += 1
             End If
         Next

But in ChildInsert.ParametrizedSQL.cst we can see that:

        For Each a As IAssociation In Entity.Associations.Where(Function(assoc) assoc.AssociationType = AssociationType.OneToMany OrElse assoc.AssociationType = AssociationType.ZeroOrOneToMany OrElse assoc.AssociationType = AssociationType.ManyToMany)
            If IsChildBusinessObject(a) Then
                childCount += 1
            End If
        Next

The childCount var is used later to call to FieldManager.UpdateChildren, but 
instead, the following lines are generated in ChildInsert:

            ' A child relationship exists on this Business Object but its type is not a child type (E.G. EditableChild). 
            ' TODO: Please override OnChildInserted() and insert this child manually.
            'FieldManager.UpdateChildren(<%= Entity.BuildUpdateChildrenParametersVariables(true) %>)

I think the correct in ChildInsertParametrizedSQL.cst is to have in account the 
SwitchableObjects, as in ChildUpdateParametrizedSQL.cst.

Original issue reported on code.google.com by bernyrod...@gmail.com on 29 Sep 2012 at 7:58

GoogleCodeExporter commented 9 years ago

Original comment by bniemyjski on 1 Oct 2012 at 1:21