Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Primary key on model Model_Challenges_Type cannot be changed.
  • Getting this error message when trying to delete a challenge model.

    We thought it was the fact that we had a $_belongs_to relationship from the type to the challenge so we removed it but that doesn't seem to be the case.

    Any help is greatly appreciated and if you have any questions, please ask.

    Here is a gist with the two models: 


    Thanks!

  • Saw your question on IRC.

    There are a few things I think are wrong:

    1. you ALWAYS need to define the relation both ways. And your "type" model is missing the definition.
    2. the rule for defining relations is that the "belongs_to" side of the relation ALWAYS  has the foreign key.

    You define:

        protected static $_has_one = array(
            'challenge_type' => array(
                'model_to' => 'Model_Challenges_Type',
                'key_from' => 'type',
                'key_to' => 'id',
                'cascade_save' => false,
                'cascade_delete' => false,
            ),

    which indicates this model has the FK, and the PK is in the related model. Which means this should be a "belongs_to", and the related model needs a "has_one".

Howdy, Stranger!

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

In this Discussion