Giter VIP home page Giter VIP logo

Comments (21)

mootensai avatar mootensai commented on June 15, 2024

could you give me a sample POST array?

from yii2-relation-trait.

kidzen avatar kidzen commented on June 15, 2024

same here...
It retun false because relation is not filled..

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

Please give me an Array sample

from yii2-relation-trait.

kidzen avatar kidzen commented on June 15, 2024

capture

from yii2-relation-trait.

kidzen avatar kidzen commented on June 15, 2024
    public function loadAll($POST, $skippedRelations = [])
    {
        if ($this->load($POST)) {
            $shortName = StringHelper::basename(get_class($this));
            $relData = $this->getRelationData();
            foreach ($POST as $model => $attr) {
                if (is_array($attr)) {
                    if ($model == $shortName) {
                        foreach ($attr as $relName => $relAttr) {
var_dump($POST);
var_dump($attr);
die;
//here where the function fail since $relAttr is an array but not a relation
                            if (is_array($relAttr)) {
                                $isHasMany = !ArrayHelper::isAssociative($relAttr);
                                if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
                                    continue;
                                }

                                return $this->loadToRelation($isHasMany, $relName, $relAttr);
                            }
//here you should handle where to save if no relation were filled
                            // return true;
                        }
                    } else {
                        $isHasMany = is_array($attr) && is_array(current($attr));
                        $relName = ($isHasMany) ? lcfirst(Inflector::pluralize($model)) : lcfirst($model);
                        if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
                            continue;
                        }

                        return $this->loadToRelation($isHasMany, $relName, $attr);
                    }
                }
            }
        }
        return false;
    }

from yii2-relation-trait.

kidzen avatar kidzen commented on June 15, 2024
  public function loadAll($POST, $skippedRelations = [])
    {
        if ($this->load($POST)) {
            $shortName = StringHelper::basename(get_class($this));
            $relData = $this->getRelationData();
            foreach ($POST as $model => $attr) {
                if (is_array($attr)) {
                    if ($model == $shortName) {
                        foreach ($attr as $relName => $relAttr) {
var_dump($POST);
var_dump($attr);
die;
//here where the function fail since $relAttr is an array but not a relation
                            if (is_array($relAttr)) {
                                $isHasMany = !ArrayHelper::isAssociative($relAttr);
                                if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
                                    continue;
                                }

                                return $this->loadToRelation($isHasMany, $relName, $relAttr);
                            }
//here you should handle where to save if no relation were filled
                            // return true; //by returning true here seems valid..but please recheck if i miss anything
                        }
                    } else {
                        $isHasMany = is_array($attr) && is_array(current($attr));
                        $relName = ($isHasMany) ? lcfirst(Inflector::pluralize($model)) : lcfirst($model);
                        if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
                            continue;
                        }

                        return $this->loadToRelation($isHasMany, $relName, $attr);
                    }
                }
            }
        }
        return false;
    }

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

which array is not loaded? Contract array should be loaded right? Maybe awarded_date-contract-awarded_date-disp array not loaded? Or is it Contract array also not loaded?
If it's Contract array which is not loaded, then maybe your load() function is not working meaning maybe your attribute is not safe

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

@kidzen problem is different than @matthiasrust

@matthiasrust is valid, @kidzen need to re-confirm

@matthiasrust I need your Array sample

from yii2-relation-trait.

a10317 avatar a10317 commented on June 15, 2024

Hi,
I have the same problem. In your former versionsof loadAll there was a "return true" also.
Greetings

from yii2-relation-trait.

kidzen avatar kidzen commented on June 15, 2024

The problem is not on data not get loaded..
my contract has 3 other hasMany relation attached to it..
the data get loaded succesfully, but if i leave the relation form empty, it wont return true..

from yii2-relation-trait.

FedericoBenedetti1976 avatar FedericoBenedetti1976 commented on June 15, 2024

same issue. After update, loadAll return false on create/update. If i use "load" instead of "loadAll" it works.
But before the update, same code, same table, "loadAll" works fine.

I do another test with a simple table with no relation and loadAll return false also.

I see RelationTrait.php history and it's radically changed.
The problem is in
foreach ($attr as $relName => $relAttr) { if (is_array($relAttr)) {
for normal post (create/update) $relAttr isn't an array but has a value, so the loadAll function always return false.

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

may i get your POST array sample @Lordfef

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

Please try again..

from yii2-relation-trait.

FedericoBenedetti1976 avatar FedericoBenedetti1976 commented on June 15, 2024

i run "composer update" but there's no update for this repo.

Next a simple table that works before last release

MODEL:

<?php

namespace common\models\db\base;

use Yii;

/**
 * This is the base model class for table "mag_causali".
 *
 * @property integer $id
 * @property string $nome
 * @property string $segno
 *
 * @property \common\models\db\MagMov[] $magMovs
 */
class MagCausali extends \yii\db\ActiveRecord
{
    use \mootensai\relation\RelationTrait;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['nome'], 'string', 'max' => 45],
            [['segno'], 'string', 'max' => 1]
        ];
    }
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mag_causali';
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'nome' => 'Nome',
            'segno' => 'Segno',
        ];
    }
    
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMagMovs()
    {
        return $this->hasMany(\common\models\db\MagMov::className(), ['id_cau' => 'id']);
    }
    }

CONTROLLER:


    /**
     * Creates a new MagCausali model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new MagCausali();

        if ($model->loadAll(Yii::$app->request->post()) && $model->saveAll()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }

$_POST:

Array (
[_csrf-backend] => vV0binF5STbOYr4ozCClGDRtWmPmBVIB1BmWq1KbRrEwjHYdvVu___Qs_PORm3S1d1mkQYmNdw9wq7eJ8jo62Q==
[MagCausali] => Array (
[id] =>
[nome] => test
[segno] => +
)
) 

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

change your composer to dev-master or on terminal
$ composer require 'mootensai/yii2-relation-trait:dev-master'

from yii2-relation-trait.

FedericoBenedetti1976 avatar FedericoBenedetti1976 commented on June 15, 2024

Must i regenerate Model and Crud with yii-enhanced?

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

no need..

from yii2-relation-trait.

FedericoBenedetti1976 avatar FedericoBenedetti1976 commented on June 15, 2024

Well. I do different test.
I can say the problem "loadAll" now is OK. Goog work, thank's.

I ask you if must i regenerate model and crud, because, after the creation success, the controller load the view, and the view give the error:
Invalid Configuration – yii\base\InvalidConfigException Please specify the "model" property.
I know it's another issue.
But i see that in the view file generated from gii-enhanced there is a control for the first GridView of relations with if($providerRELATION->totalCount){.... , but the control is missing after for the DetailView of relations.

from yii2-relation-trait.

a10317 avatar a10317 commented on June 15, 2024

LoadAll - error is fixed – everything works
Thank you for your efforts

from yii2-relation-trait.

brian3t avatar brian3t commented on June 15, 2024

Thanks for the fix.
Please mark this fix as a release, otherwise many people will encounter this same error.

Great job.

from yii2-relation-trait.

mootensai avatar mootensai commented on June 15, 2024

Done! Thanks @brian3t

from yii2-relation-trait.

Related Issues (20)

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.