IsraelOrtuno / Eavquent

EAV modeling package for Laravel and Eloquent – This package is abandoned, please use this fork https://github.com/rinvex/attributes
63 stars 14 forks source link

Relations over EAV #18

Closed dkulyk closed 8 years ago

dkulyk commented 8 years ago

It is necessary to check the value of relationships through EAV

IsraelOrtuno commented 8 years ago

Can you be clearer at this point please?

Do yo mean to work with raw queries / query builder instead?

dkulyk commented 8 years ago

Eloquent uses lazy loading relationships, so it is possible to establish a relationship with EAV

class Client2 extends Model
{
    use Propertier;
    protected $table = 'clients';
    public function parent()
    {
        return $this->belongsTo(Client2::class, 'parent_id');
    }
}

parent_id is property.

$client = Client2::query()
        ->with('properties')
        ->with('parent')
        ->first();

Result:

array:4 [
  "id" => 1
  "parent_id" => 2
  "parent" => array:3 [
    "id" => 2
    "parent_id" => null
  ]
]
IsraelOrtuno commented 8 years ago

I do not really understand this. Could you try to explain it in other way?

On Tuesday, 2 February 2016, Dmytro Kulyk notifications@github.com wrote:

It uses lazy loading relationships, so it is possible to establish a relationship with EAV

class Client2 extends Model{ use Propertier; protected $table = 'clients'; public function parent() { return $this->belongsTo(Client2::class, 'parent_id'); }}

parent_id is property.

$client = Client2::query() ->with('properties') ->with('parent') ->first();

Result:

array:4 [ "id" => 1 "parent_id" => 2 "parent" => array:3 [ "id" => 2 "test" => [] "parent_id" => null ] ]

— Reply to this email directly or view it on GitHub https://github.com/IsraelOrtuno/Propertier/issues/18#issuecomment-178701870 .

Un saludo Israel Ortuño

dkulyk commented 8 years ago

EAV property is used as a key to relationships. It works. Do not do anything.