This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

d3monfiend15105
d3monfiend15105

I read a documentation about database trait and come across this trait. I want my back end view to have a parent tree that have children of a different model.

Model A has many Model B children and i want to see the children in model A's view. I can't make the tree work and i saw some plugin use this but its only for single model. The documentation reads, i quote,"A simple tree model will use the parent_id column maintain a parent and child relationship between models." "Between MODELS" mean multiple model right?

So what i did was:

ModelA.php {$primaryKey = 'parent_id';$hasMany = ['children' => ['author\plugin\models\modelb', 'key' => 'parent_id']];}

create_modela_table.php {$table->increment('parent_id');$table->primary('parent_id');}

config_list.yaml {showtree: true}

This cause error say multiple primary key defined. So i change to:

create_modela_table.php {$table->integer('parent_id');$table->primary('parent_id');}

But its cause another error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'order clause' (SQL: select author_plugin_modela.* from author_plugin_modela order by id desc). I already defined primary key to parent_id and i can't put increment on parent_id. Why i can't make parent_id as the key?

I don't really understand how Simpletree trait is suppose to be used. And how to defined primary key in the model class. I tried but its does not matter.

Last updated

d3monfiend15105
d3monfiend15105

Does anyone know how to use simpletree?

jan-vince
jan-vince

Can you be more specific about this?

Please give us some example of data you want to manage and what results you need.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.