FastEasyMapping icon indicating copy to clipboard operation
FastEasyMapping copied to clipboard

Never ending recursion

Open rajatkj opened this issue 7 years ago • 1 comments

Suppose if there is a Parent which has children array inside it and those children also has a children array in It... and so on. This will end when a child doesn't have any more children.

I create a mapping Function for creating a representation and In core DB I have a to many relationship from children to children.

That method that creates a representation i.e. FEMapping for mapping that data.

func parentMapper() -> FEMMapping {

        let mapping = FEMMapping(entityName: “Parent”)

        mapping.primaryKey = “id”

        mapping.addAttributes(from: [“key”, "id", “value”])

        mapping.addToManyRelationshipMapping(parentMapper(), forProperty: “children”, keyPath: “children”)
        return mapping

    }

This mapping function is recursive and never ends.

rajatkj avatar Jun 01 '18 14:06 rajatkj

Hello, @Rico9260 Recursive behaviour comes out of the recursive call to a parentMapper. What you might actually want to is:

func parentMapper() -> FEMMapping {
  let mapping = FEMMapping(entityName: “Parent”)
  mapping.primaryKey = “id”
  mapping.addAttributes(from: [“key”, "id", “value”])

  // this will setup a recursive mapping
  mapping.addRecursiveToManyRelationship(forProperty: "children", keypath: "children")

  return mapping
}

dimazen avatar Jun 01 '18 16:06 dimazen