Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisionable not creating revision entries for belongsToMany relationships #402

Open
commadelimited opened this issue Sep 27, 2021 · 1 comment

Comments

@commadelimited
Copy link

I have a Product model and a Category model. The Product model has a belongsToMany relationship with Category

/**
 * App\Models\Product.
 *
 * @property int $id
 * @property string $name
 * @property string $url
 * @property string $description
 * @property \Illuminate\Support\Carbon|null $created_at
 */
class Product extends Model {
    use RevisionableTrait;

    public $guarded = ['id'];

    public function categories() {
        return $this->belongsToMany(Category::class, 'product_category');
    }
}

/**
 * App\Models\Category.
 *
 * @property int $id
 * @property string|null $parent_category_id
 * @property string $name
 * @property string $description
 */
class Category extends Model {
    public $guarded = ['id'];
    public $timestamps = false;
}

When I save a Product I get the expected results of records inserted into the revisions table. However I'm also like to see records inserted when categories are added or removed. How would I accomplish this given that product_category doesn't have it's own model?

@Taelkir
Copy link

Taelkir commented Feb 22, 2022

I know from your other issue that you aren't looking into this package anymore, but if anyone else comes looking, here's a SO answer with a possible work around for this missing functionality: https://stackoverflow.com/a/37952887/10228954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants