class Recipes extends Entities
{
public function initialize() {
parent::initialize();
$this->hasManyToMany(
'id',
'PhalconRest\Models\Entities\RecipeIngredients',
'idRecipe', 'idIngredient',
'PhalconRest\Models\Entities\Ingredients',
'id',
array('alias' => 'recipeIngredients')
);
....
}
....
}
[columns]
recipe => id,recipe,..
ingredients => id,ingredients,origin,..
recipeIngredients => id,idRecipe,idIngredient,measure,cookingSecret,isDelivery
[create point]
$oRecipe = new EntityRecipes();
....
foreach( $data->ingredients as $ingredient)
{
$oRecipeIngredient = new EntityRecipeIngredients();
$oRecipeIngredient->assign( (array)$ingredient);
$aRecipeIngredients[] = $oRecipeIngredient;
}
....
return $oRecipe->create();
[posting data]
....
"ingredients":
[{
"idIngredient":135,
"measure":"",
"cookingSecret":false,
"isDelivery":true
}],
....
[error]
1 [internal function]: Phalcon\Mvc\Model->fireEvent('onValidationFai...')
2 [internal function]: Phalcon\Mvc\Model->_preSave(Object(Phalcon\Mvc\Model\MetaData\Memory), false, 'idrecipe_ingred...')
3 [internal function]: Phalcon\Mvc\Model->save()
4 [internal function]: Phalcon\Mvc\Model->_postSaveRelatedRecords(Object(Phalcon\Db\Adapter\Pdo\Mysql), Array)
5 [internal function]: Phalcon\Mvc\Model->save(NULL, NULL)
6 /library/webserver/api/models/Repositories/Repository/Recipes.php(217): Phalcon\Mvc\Model->create()
7 /library/webserver/api/controllers/RecipesController.php(33): PhalconRest\Models\Repositories\Repository\Recipes->Add(Object(stdClass))
8 [internal function]: PhalconRest\Controllers\RecipesController->UploadRecipe()
9 [internal function]: Phalcon\Mvc\Micro\LazyLoader->__call('UploadRecipe', Array)
10 [internal function]: Phalcon\Mvc\Micro\LazyLoader->UploadRecipe()
11 /library/webserver/api/index.php(199): Phalcon\Mvc\Micro->handle()
12 /library/webserver/api/index.php(204): App->main()
13 {main}
"idRecipe": "Value of field idRecipe must be numeric"
i got this error msg.
Is it wrong to use?