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 cannot be changed.
  • Been using FuelPHP for awhile now, and this is the first time I've seen this. I have two models \Model\Trip and \Model\Trip_Category as seen below. When trying to delete a Trip with the code below, I receive the error "Fuel\Core\FuelException [ Error ]: Primary key on model Model\Trip_Category cannot be changed." Not sure why it would do this since it really doesn't make sense in my opinion. 

    Regardless of the issue, I need to be able to access the categories for a trip through $t->category and get the categories of a trip through $category->trips.

    Delete Code:
    $t = \Model\Trip::find($id);
    $t->delete( false );


    Thanks in advance!
  • Your trip-category relation is the wrong way around.

    Easiest to remember: the model that contains the foreign key must have the "belongs_to" part of the relation.

    category_id is in Trip, therefore that should have the belongs_to, not the 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