Skip to content

getEavAttribute('attributeName') returns no data #9

@alexglue

Description

@alexglue

Model.php:

            'eavAttr' => array(
                'class' => 'application.components.behaviors.EEavBehavior',
                'tableName' => 'project_eav',
                'entityField' => 'project_id',
                'safeAttributes' => [], //empty array! btw, I have three eav-fields for this model
                'preload' => false, //preload false!
                'cacheId' => 'cache'
            )

i have three attributes stored in db for Model->id instance:
attribute1=OK
attribute2=OK
attribute3=OK

Now, you should turn on CMemCache etc,
then make flush_all; //!important
and use in template smth like this:
$appealText = $this->project->getEavAttribute('attribute1'); //it's OK!
$appealText = $this->project->getEavAttribute('attribute2'); //it's NULL!
$appealText = $this->project->getEavAttribute('attribute3'); //it's NULL!

Thats all folks! you have a broken cache data!

The possible solution are following:

  1. do not use 'safeAttributes' => [], with empty array
  2. or do not use preload = false with empty array!
  3. or use smth like this:
$eavAttributes = $this->project->getEavAttributes(['attribute1','attribute2','attribute3']);

before getting the first one!

The root of evil is:

    public function getEavAttribute($attribute) {
        $values = $this->getEavAttributes(array($attribute)); //storing to cache only the first value!
        return $this->attributes->itemAt($attribute);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions