mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.01k stars 1.43k forks source link

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

Open busaku opened 6 months ago

busaku commented 6 months ago

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');
    }
  2. Run $model->relation()->toMql();
  3. -> 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

GromNaN commented 1 month ago

May be related to PHPORM-226 https://github.com/mongodb/laravel-mongodb/pull/3093