Comments (21)
could you give me a sample POST array?
from yii2-relation-trait.
same here...
It retun false because relation is not filled..
from yii2-relation-trait.
Please give me an Array sample
from yii2-relation-trait.
from yii2-relation-trait.
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.
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.
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.
@kidzen problem is different than @matthiasrust
@matthiasrust is valid, @kidzen need to re-confirm
@matthiasrust I need your Array sample
from yii2-relation-trait.
Hi,
I have the same problem. In your former versionsof loadAll there was a "return true" also.
Greetings
from yii2-relation-trait.
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.
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.
may i get your POST array sample @Lordfef
from yii2-relation-trait.
Please try again..
from yii2-relation-trait.
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.
change your composer to dev-master or on terminal
$ composer require 'mootensai/yii2-relation-trait:dev-master'
from yii2-relation-trait.
Must i regenerate Model and Crud with yii-enhanced?
from yii2-relation-trait.
no need..
from yii2-relation-trait.
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.
LoadAll - error is fixed – everything works
Thank you for your efforts
from yii2-relation-trait.
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.
Done! Thanks @brian3t
from yii2-relation-trait.
Related Issues (20)
- record deleted immediately after insert HOT 8
- Too few arguments to function app\models\base\Dokter::getListDokterRS(), 0 passed and exactly 1 expected HOT 5
- ArgumentCountError Too few arguments to function app\models\base\Poli::getListPoli(), 0 passed and exactly 1 expected
- Error : Too few arguments to function app\models\base\Penilaian::getPenilaianDetsWithParam(), 0 passed and exactly 1 expected
- Unable to locate message source for category 'mtrelt'. HOT 2
- $notDeletedPK - ID's of models came null
- Filtered record being deleted on update HOT 8
- Can't save hasMany relation without index 0 (zero)
- Deletion of has many relation works wrong HOT 1
- update failed with no relation HOT 1
- The object being updated is outdated. HOT 5
- $this->relatedRecords is empty HOT 1
- working with Taggable Behavior
- ID column for Related model doesn't populate on Post
- AR Method afterSave() of related model will be marked as deleted HOT 1
- This extension is pure shit and should be deleted !!! HOT 2
- Feature Request: softDelete()
- deleteWithRelated only works with direct relations
- SaveAll() function Deletes Related Records unexpectedly. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-relation-trait.