OctoberCMS BelongsTo Relationship Saving Problem
I have two models:
I can display all brands via belongsTo function. Problem is when I try to save same brand two times, I get error duplicated entry.
This belongsTo is causing duplicated entry error when saving to DB two same brands.
public $belongsTo = [ 'brand' => [\Slasher\Farming\Models\Brands::class, 'key' => 'id'], ];
This belongsToMany works, and save's data to DB, but is generating checkbox field (I only want to select one brand at one mod enty). I'm using pivot table for this relation.
public $belongsToMany =[ 'brand' =>[ 'Slasher\Farming\Models\Brands', 'table' => 'slasher_farming_mods_brands', 'order' => 'brand_name' ], ];
BelongsTo example: (Brands are visible and I can save them. But problem is when saving same brand for more than two times).
Error I get when saving with belongsTo.
I tried also creating inverse relationships on Brands model with (belongsTo and belongsToMany), but still getting this error.
What type of relation should I make, to save Brands as dropdown list and to fix this duplicate error?
I fixed this problem with changing column in the mods name
brand_id and also changing belongsTo relation. I just removed key, and it works like a charm. No need for pivot table here.
public $belongsTo = [ 'brand' => ['Slasher\Farming\Models\Brands'] ];
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms