Closed josefch closed 1 year ago
Thanks for such a detailed issue - I was able to reproduce the issue straight away!
Is there any reason you aren't using native Eloquent pivot tables for the people <-> category relationships rather than creating your own intermediary model?
The reason I ask is because it would be much easier from Runway's perspective for you to have a HasMany field on both people & categories which can link to each other and get rid of the middle table (which I'm struggling to make work the way it is).
The database structure would stay pretty much the same.
Thanks Duncan, well I changed my models to have toMany relations, PersonCategory still has the two belogsTo - but that doesn't change anything in the problem for me, still getting [id] errors - what else would I need to change to get it working? Blueprints having the handles categories and people as named in the models but seeing numerical IDs in the form still, any help appreciated...
class Person extends Model
{
protected $table = 'person';
public $timestamps = false;
protected $fillable = [
'name'
];
public function categories()
{
return $this->belongsToMany(Category::class, 'person_category', 'person', 'category')
->withPivot('id');
}
}
class Category extends Model
{
protected $table = 'category';
public $timestamps = false;
protected $fillable = [
'name'
];
public function people()
{
return $this->belongsToMany(Person::class, 'person_category', 'category', 'person')
->withPivot('id');
}
}
Get rid of the PersonCategory
model from Runway & it's blueprint.
Then change the people/category fields on both sides to HasMany fields.
Thanks Duncan, that did the trick, working very well now - brilliant - THANKS
Awesome, glad you hear it! I'll close this issue now.
Description
I have an entry that has_many other rows that themselves refer to a belongs_to row, for example a person can have many categories that have a 1:1 relationship to category which holds the name.
When I setup (migrations/models and blueprints below) and edit a person I'm unable to save a choosen category (from the select), instead of inserting the id it tries to save [id] instead, errors like:
[19:33:08] LOG.error: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type integer: "[2]" CONTEXT: unnamed portal parameter $1 = '...' (SQL: insert into "person_category" ("category") values ([2]) returning "id")
On top (if I add manually in the database) I get
Categories 3
in the form - so instead of showing the name of the category I get the ID of it (which is clickable/editable - but leads to the above error). I hope it's understandable/reproduceble - hope there's a fix for it...
Steps to reproduce
Migrations:
The models:
runway.php
Blueprints
person.yaml
person_category.yaml
category.yaml
Environment
Application Name: Laravel Laravel Version: 9.45.1 PHP Version: 8.1.13 Composer Version: 2.4.2 Environment: local Debug Mode: ENABLED URL: laravel Maintenance Mode: OFF
Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED
Drivers Broadcasting: log Cache: statamic Database: pgsql Logs: stack / single Mail: smtp Queue: sync Session: file
Statamic Addons: 1 Antlers: regex Stache Watcher: Enabled Static Caching: Disabled Version: 3.3.64 PRO
Statamic Addons doublethreedigital/runway: 2.6.3