dillingham / nova-attach-many

BelongsToMany create / edit form component for Nova
MIT License
271 stars 107 forks source link

Error using custom relatedKey in belongsToMany #69

Closed alberto-bottarini closed 3 years ago

alberto-bottarini commented 4 years ago

BelongsToMany relationship allows you to define which model key will be used in pivot table. Primary Key is the default, but you can override it using:

class Rule {
    public function websites()
    {
        return $this->belongsToMany(Website::class, 'rule_website', 'rule_id', 'website_code', 'id', 'code');
    }
}

AttachMany fields send ids to the controller and use sync method to attach/detach related models. It should use relatedKey (code in the example) instead of id.

alberto-bottarini commented 3 years ago

Fixed by https://github.com/dillingham/nova-attach-many/pull/62