kodeine / laravel-meta

Fluent Meta Data for Eloquent Models, as if it is a property on your model
MIT License
400 stars 90 forks source link

whereMeta with table name #83

Closed dhcmega closed 2 years ago

dhcmega commented 3 years ago

Hi! I think that whereMeta trait should control that the column names "key" and "value" are properly prepended with table name to avoid any case of ambiguity:

->where($this->getMetaTable() . '.key', '=', $key)->where($this->getMetaTable() . '.value', '=', $value)

    /**
     * whereMeta scope for easier join
     * -------------------------
     */
    public function scopeWhereMeta($query, $key, $value, $alias = null)
    {
        $alias = (empty($alias)) ? $this->getMetaTable() : $alias;
        return $query->join($this->getMetaTable() . ' AS ' . $alias, $this->getQualifiedKeyName(), '=', $alias . '.' . $this->getMetaKeyName())->where($this->getMetaTable() . '.key', '=', $key)->where($this->getMetaTable() . '.value', '=', $value)->select($this->getTable() . '.*');
    }