laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

morphOne $model (mysql) -> relation (mongo)

Open busaku opened this issue 2 months ago • 0 comments

  • Laravel-mongodb Version: 4.2.0
  • PHP Version: 8.3.4
  • Database Driver & Version: php8.3-mongodb latest

Description:

I have a model with a mysql collection e.g. $product. with a meta-field relation (morphOne) to a MetaData model (mongoDB). $this->meta()->toMql() will show a query like { $and: [{"meta.metable_id": "<prodId>", "meta.metable_type": "<prodEntity>"}]} But: I dont know where the meta. prefix comes from. If you just create a $this->meta()->make() Model. The values got prefilled correcty (just metable_id and metable_type, without meta. prefix)

Steps to reproduce

  1. Create a morhOne relationShip inside a model who uses a mysql-db:
public function meta(): MorphOne
    {
        return $this->morphOne(MetaData::class, 'metable');
    }

add it to a MetaData model who use mongoDB

    public function metable(): MorphTo
    {
        return $this->morphTo(__FUNCTION__, 'metable_type', 'metable_id');
    }
  1. Run $model->relation()->toMql();
  2. -> see the result with the wrong relation-fields prefixed with meta.

(It did not happend if the $model is an Mongo-Model too!)

Expected behaviour

Use the correct field names (not prefixed with meta.)

Actual behaviour

It put the prefix meta. in front of "metable" field names

busaku avatar Apr 16 '24 13:04 busaku