0

I'm currently building a Website with OctoberCMS and i have a Database Products with a list of Products. Those Products should be linked to other Products of the Same table. I have tried to achieve that trough a Pivot Table. Can it be done?

My fields.yaml:

 fields:
name:
    label: Produkt
    oc.commentPosition: ''
    span: auto
    type: text
active:
    label: Aktiv
    span: auto
    default: 1
    type: switch
content:
    label: Beschreibung
    size: ''
    oc.commentPosition: ''
    span: auto
    type: richeditor
sorting:
    label: Sortierung
    oc.commentPosition: ''
    span: auto
    type: number
products:
    label: Relation
    oc.commentPosition: ''
    nameFrom: name
    descriptionFrom: description
    span: auto
    type: relation

My columns.yaml:

 fields:
name:
    label: Produkt
    oc.commentPosition: ''
    span: auto
    type: text
active:
    label: Aktiv
    span: auto
    default: 1
    type: switch
content:
    label: Beschreibung
    size: ''
    oc.commentPosition: ''
    span: auto
    type: richeditor
sorting:
    label: Sortierung
    oc.commentPosition: ''
    span: auto
    type: number
products:
    label: Relation
    oc.commentPosition: ''
    nameFrom: name
    descriptionFrom: description
    span: auto
    type: relation

Relation:

    public $belongsToMany = [
    'products' => [
        'XXX\Produkte\Models\Produkt',
        'table' => 'XXX_produkte_relations'
    ]
];

Screenshot of my Pivot Table: Pivot-Table

The Result should be a Pivot Table with two ids of the two selected Products.

I get one entry in my Pivot Table but not the second id. Thanks for any Help!

Lucas_Bo
  • 142
  • 1
  • 9
  • can you share more details about that pivot table which extra fields you need to add in pivot table, (generally pivot table used to store relation as well some extra values or data for that relation) if that is not needed then you are just good with self relation no need for pivot table. if you don't need pivot table you can use https://octobercms.com/docs/database/traits#simple-tree simple tree here they give category example you can use it for products. – Hardik Satasiya Dec 07 '17 at 11:35
  • I added a Screenshot of the Pivot-Table, maybe this helps to point out my error. – Lucas_Bo Dec 07 '17 at 12:01
  • ok ok got it I will do little debug on this and let you know – Hardik Satasiya Dec 07 '17 at 12:42
  • Thanks allot, but i have resolved it. Had to add a second Model witch refers to the same table to handle the relations. – Lucas_Bo Dec 07 '17 at 14:25
  • hmm..., cool :) – Hardik Satasiya Dec 07 '17 at 16:28

0 Answers0