Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Need Help : ORM Error Deleting - Primary key on model Model_Test cannot be changed.
  • Hello.., 
    I'm using Xampp and FuelPHP v1.6.1 and then v1.7.1. and working with ORM with no problem..., but then FuelPHP1.7.2 is released and I try to use this release to develop a website.
    and then I'm having a problem when using ORM relation. it works fine with displaying (read)., but I find some trouble with deleting.., please help me to fix this problem. in short:
    1. I'm using oil scaffold to generate code 
    a. "oil scaffold test code:varchar[15]"  
    b. "oil scaffold anothertest code:varchar[15] test_id:int" 

    2. in the generated code - Model_Anothertest- I add "has_one" relation 

    protected static $_has_one = array(
    'test' => array('key_to' => 'id', 'key_from'=>'test_id'),
        );


    3. in "view/anothertest/index.php" I changed the code to display the relation
    before : $items->test_id;
    after : $item->test->code;

    4. when executing controller "anothertest/index" it show the relation correctly but when I try to delete it and error issued Primary key on model Model_Test cannot be changed.

    Can anyone help me to fix this .... Its new to me because when I uses Fuel 1.6.1 or 1.7.1 it works fine before.., 
    but now neither FuelPHP 1.7.1 or 1.7.2 work in the same PC I use...

    please help me.., 
    great thanks before

  • Please help me
  • Harro VertonHarro Verton
    Accepted Answer
    As far as I know that has never changed.

    You need to define your relations both ways, so you need (in this case) a has_one and a belongs_to. The model that contains the foreign key MUST have the belongs to.

    If you look at your has_one definition, you have it the wrong way around, assuming "test_id" is your FK.

    This has always been the case, so I don't believe this would have worked in 1.6.1.
  • stupid me... :-p
    I'm wrong in understanding it...
    Thanks for your super fast response..., it work now... :)
    tQ
  • Just remember that "belongs_to" is always defined on the model that has the FK, and you're good to go.

Howdy, Stranger!

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

In this Discussion