Coder Social home page Coder Social logo

eav-behavior's People

Contributors

cebe avatar chemezov avatar creocoder avatar samdark avatar slavcodev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eav-behavior's Issues

Trying to loadEavAttributes on empty owner model returns corrupteed SQL

Action for create an object::view

    <?php
    if(!$model->isNewRecord) $model->getEavAttributes();
    foreach (['attr1', 'attr2', 'attr3'] as $name){?>
        <?= $form->textAreaGroup($model,'eavAttributes['.$name.']', array('widgetOptions'=>array(
            'htmlOptions'=>array('rows'=>6, 'cols'=>50)
        ))); ?>
    <?}?>

calling this:

    public function loadEavAttributes($attributes)

and now we have smth like this on empty object primary key (new entity adding):

SELECT * FROM `project_eav` `t` WHERE (object_id = ) AND (attribute IN (:ycp0, :ycp1, :ycp2))

The solution is to fix EEavBehavior:

    public function loadEavAttributes($attributes) {
        if(is_null($this->getModelId())){ //[+]
            return $this->getOwner(); //[+]
        } //[+]

getEavAttributes not returning full array

I have used to getEavAttributes() function and I am not getting returned a full array if I have many rows with the same entity and attribute. The most I get in an array is 2 and then its getting overwritten with the next result as it itterate through on loadEavAttributes().

Any ideas?

Filter by multiple values of attr with OR logic

Hi! I'm using this behavior but i can't make it works with OR logic.
If i want to find items with several different values of attribute at the same time, i get empty result
I think it's because several values of one attribute work like AND logic. How to switch it to OR logic?

Опечатка с self::t

EEavBehavior.php:211
должно быть Yii::t('yiiext', ...
а сейчас self::t('yii',...
что естественно вызывает Exception т.к. EEavBehavior::t не существует.

Save an already existing attribute creates a new one.

How to reproduce:

$model = Model::model()->findByPk($pk);
$model->setEavAttribute('attribute', 'value');
$model->save();

Now there's two records at the EavAttr table for the same entity and attibute.

Any guidance?

TIA!

updates

is this an active extension?
any updates?
is this good approach to design applications?

getEavAttribute('attributeName') returns no data

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);
    }

Баг множественного выбора в одном атрибуте

Доброе утро!

Работаю с движком Eximus. И недавно исправлял баг Множественного выбора. Вот описание исправленного бага из трекера багов и задач Eximus'а:

После выбора множественных атрибутов, движок ищет все товары по критерию. Однако, в расширении EEavBehavior было немного другое трактование условия множественного выбора. Если пришел массив со значениями для одного атрибута, то EEavBehavior делал составной JOIN, в котором по всем значениям из массива делал склейку - т.е. это даже не точное соответствие товара всем значениям при перечислении через AND, а сложный запрос с пропорциональным количеством JOIN'ов, в каждом из которых идет проверка на соответствие.

Решение: если в EEavBehavior приходит массив со значениям для атрибута, то сделал проверку на вхождение в массив через IN.

Вот изменение в функции protected function getFindByEavAttributesCriteria($attributes){:

Было:

    foreach ($values as $value) {
        $value = $conn->quoteValue($value);
        $criteria->join .= "\nJOIN {$this->tableName} eavb$i"
            .  "\nON t.{$pk} = eavb$i.{$this->entityField}"
            .  "\nAND eavb$i.{$this->attributeField} = $attribute"
            .  "\nAND eavb$i.{$this->valueField} = $value";
            $i++;
    }

Стало:
    $valueTmpArr = array();
    foreach ($values as $value) {
        $valueTmpArr[] = $conn->quoteValue($value);               
    }

    $valueInCondition = implode(',',$valueTmpArr);

    $criteria->join .= "\nJOIN {$this->tableName} eavb$i"
        .  "\nON t.{$pk} = eavb$i.{$this->entityField}"
        .  "\nAND eavb$i.{$this->attributeField} = $attribute"
        .  "\nAND eavb$i.{$this->valueField} IN ($valueInCondition)";

    $i++;   


Правильно ли я понял, что именно здесь нужно было исправить и что здесь планировался такой критерий? :)

Attribute type

Hi, excellent extension but how we can define the attribute type?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.