Hello,

juste pour poster une solution... je ne sais pas si c'est la
meilleur...
J'ai modifier mon schema.yml
schema.yml
----------------------------------------------------------------------------------------------------------------------------------
Product:
  actAs:
    Timestampable: ~
  columns:
    id: {type: string(4), primary: true, notnull: true}
    title: {type: string(200), notnull: true}
  relations:
    Products:
      class: Product
      refClass: ProductBrother
      foreign: product_brother_id
      local: product_id

ProductBrother:
  columns:
    product_id: {type: string(20), primary: true, notnull: true}
    product_brother_id: {type: string(20), primary: true, notnull:
true}
----------------------------------------------------------------------------------------------------------------------------------

Le seul hic c'est qu'à la genération de ProductForm.class.php, il y a
un widget créer pour products_list (product au pluriel) et un pour
product_list. cela est surement un comportement normal...


On 30 oct, 11:33, smellycat37 <[email protected]> wrote:
> Hello,
>
> Je ne trouve pas de solution pour créer une many to many sur la même
> table.
> Je créer mon schema.yml, je génère mes objects, mes forms... Aucun
> pb... Mes relations sont bien crées en base...
> J'édite un élément, j'ai bien ma multi selecbox.... aucun pb...
> c'est au moment de la sauvegarde d'un product ou l'on a ajouté des
> frères ou j'ai une erreur 500 :
> Not null violation: 7 ERROR: null value in column "product_brother_id"
> violates not-null constraint
>
> schema.yml
> ----------------------------------------------------------------------------------------------------------------------------------
> Product:
>   actAs:
>     Timestampable: ~
>   columns:
>     id: {type: string(4), primary: true, notnull: true}
>     title: {type: string(200), notnull: true}
>   relations:
>     Products:
>       class: Product
>       refClass: ProductBrother
>
> ProductBrother:
>   columns:
>     product_id: {type: string(20), primary: true, notnull: true}
>     product_brother_id: {type: string(20), primary: true, notnull:
> true}
>   relations:
>     Product: {onDelete: CASCADE, class: Product, local: product_id,
> foreign: id}
>     ProductBrother: {onDelete: CASCADE, class: Product, local:
> product_brother_id, foreign: id}
> ----------------------------------------------------------------------------------------------------------------------------------
>
> J'ai regardé d'où pouvait venir l'erreur afin de trouver une solution
> et voici mes conclusions:
> 1 - lors du $productForm->save();
> 2 - la method saveProductsList déclarée dans mon
> BaseProductForm.clss.php est appelée
>      A la fin de cette method est appelée l'instruction
>      $this->object->link('Products', array_values($link));
> 3 - la method link est déclarée dans l'object Record (vendor\symfony
> \lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Record.php)
> et c'est là d'où provient l'erreur :
>
>     foreach ($ids as $id) {
>         $record = new $modelClassName;
>         $record[$localFieldName] = $identifier;
>         $record[$foreignFieldName] = $id; //
>         $record->save();
>     }
>
> $localFieldName est bien égale à product_id.
> le pb est que $foreignFieldName est également égale à product_id alors
> qu'il devrait être égale à product_brother_id.
> J'imagine que cette erreur est du à mon schema.yml.
>
> Merci à ceux qui pourront m'aidé
--~--~---------~--~----~------------~-------~--~----~
Vous avez reçu ce message, car vous êtes abonné au groupe Groupe "Symfony-fr" 
de Google Groupes.
 Pour transmettre des messages à ce groupe, envoyez un e-mail à 
l'adresse [email protected]
 Pour résilier votre abonnement à ce groupe, envoyez un e-mail à 
l'adresse [email protected]
 Pour afficher d'autres options, visitez ce groupe à l'adresse 
http://groups.google.com/group/symfony-fr?hl=fr
-~----------~----~----~----~------~----~------~--~---

Répondre à