Skip to content

Adjacency list parent_id duplication messes up tree #59

@sts-ryan-holton

Description

@sts-ryan-holton

This is a bit of a longshot here, I'm using the laravel-adjacency-list package in my project. This package works by having a column on a model called parent_id, which when null denotes a root level item, then, models below it, loaded in via a children relationship may have an unlimited depth.

I have three models:

  • MarketingAutomation
  • MarketingAutomationAction
  • MarketingAutomationActionCondition

Based on these models, the MarketingAutomationAction is the model which contains the parent_id table and functionality around that package. In addition, this model also a foreign id column to marketing_automation_id.

MarketingAutomationActionCondition models are linked to actions. So in the end, we may end up with the following hierarchy:

  • Marketing automation
    • Marketing automation action
      • Marketing automation action condition
      • Marketing automation action condition
    • Marketing automation action
      • Marketing automation action
        • Marketing automation action condition
      • Marketing automation action
        • Marketing automation action
    • Marketing automation action

I've put \Bkwld\Cloner\Cloneable on all three of these models, then, I've added the following to each:

MarketingAutomation

protected $cloneable_relations = ['actions'];

MarketingAutomationAction

protected $cloneable_relations = ['children', 'conditions'];

When I attempt to clone an automation using MarketingAutomation::find(1)->duplicate(), the table structure of the. MarketingAutomationAction gets completely messed up, the parent_id column doesn't know how to relate to another model etc.

Any way to resolve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions