dimitriBouteille / wp-orm

WordPress ORM with Eloquent, an object-relational mapper that makes it enjoyable to interact with your database.
https://packagist.org/packages/dbout/wp-orm
MIT License
51 stars 5 forks source link

[BUG]: Custom models can't extend Pivot relation #75

Closed maxrice closed 1 week ago

maxrice commented 1 week ago

Describe the bug

When creating a many-to-many relationship, Eloquent allows you to define a custom model that will be used for the intermediate table. To do this, the model must extend the Pivot relation. That model is a simple wrapper over the base Model class, with a AsPivot trait.

To do this using the WP ORM library, I've extended the base AbstractModel class and added use AsPivot. However, this triggers an error:

Declaration of Illuminate\Database\Eloquent\Relations\Concerns\AsPivot::getTable() must be compatible with  Dbout\WpOrm\Orm\AbstractModel::getTable(): string

The Eloquent base Model class does not add a return type to getTable(), so it seems that in order to fully support many-to-many relationships, you'll need to remove the string return type for getTable()](https://github.com/dimitriBouteille/wp-orm/blob/develop/src/Orm/AbstractModel.php#L36-L45)

Your setup

dimitriBouteille commented 1 week ago

Hi @maxrice

Thanks for the details. I look to fix this bug as quickly as possible, you will be informed when it is done.

Best,

dimitriBouteille commented 1 week ago

Hey @maxrice

The bug has been fixed in v3.3.0 :rocket:

maxrice commented 1 week ago

wonderful, thanks!