Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Undefined variable: new_pk
  • Hi,

    i have Model_Pageadherent and Model_Horaire, with has_one relationship :

    In Model_Pageadherent :
    <code>
        protected static $_has_one = array(
            'horaire' => array(
                'key_from' => 'id',
                'model_to' => 'Model_Horaire',
                'key_to' => 'idPageAdherent',
                'cascade_save' => true,
                'cascade_delete' => true,
            )
        );
    </code>

    In Model_Horaire :
    <code>
            protected static $_belongs_to = array(
                'pageAhderent' => array(
                    'key_from' => 'idPageAdherent',
                    'model_to' => 'Model_Pageadherent',
                    'key_to' => 'id',
                    'cascade_save' => false,
                    'cascade_delete' => false,
            ));
    </code>

    For the moment, existing "Pageadherent" has not linked to them "Horaire".
    I want to create "Horaire", and link him to "Pageadherent", my code :

    <code>
                if (!$pageAdherent->horaire) {
                    $pageAdherent->horaire = new Model_Horaire(Model_Horaire::$defaults);
                    $pageAdherent->save();
                }
    </code>

    My static array $defaults in Model_Horaire :
    <code>
            public static $defaults = array(
                'lundi' => 'de 14 h 00 à 19 h 00',
                'mardi' => 'de 9 h 30 à 19 h 00',
                'mercredi' => 'de 9 h 30 à 19 h 00',
                'jeudi' => 'de 9 h 30 à 19 h 00',
                'vendredi' => 'de 9 h 30 à 19 h 00',
                'samedi' => 'de 9 h 30 à 19 h 00',
            );
    </code>

    I don't understand the mistake ...

    The error message :

    ErrorException [ Notice ]: Undefined variable: new_pk

    PKGPATH/orm/classes/model.php @ line 1497

  • Note: If $pageAdherent is new, it's work. But i can't link "Horaire" on existing $pageAdherent..
  • That looks like a bug.

    Can you create an issue for it at https://github.com/fuel/orm/issues so it can be looked at?
  • Ok, the link to my issue : https://github.com/fuel/orm/issues/233

    Note: It's work if i do this : 

    ```php
                if (!$pageAdherent->horaire) {
                    $horaire = Model_Horaire::forge(Model_Horaire::$defaults);
                    $horaire->idPageAdherent = $pageAdherent->id;
                    $horaire->pageAdherent = $pageAdherent;
                    $horaire->save();
                    $pageAdherent->horaire = $horaire;
                }
    ```

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion