Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
model without id
  • I have a model tmtrace, that requires a timestamp as a PK. Hence, id not needed... If id were to be defined as PK, then that would create an "create anomaly" as it would be possible to insert the same value twice...

    FuelPHP tells me: "Property "id" not found for Model_Tmtrace."  when I define the model without the id field.. What is the right way of doing this? Should I define an id field and not set it to PK just to make the interpreter(or compiler.. or what applies) happy? 
  • HarroHarro
    Accepted Answer
    No, you should define the correct primary key in your model. Every ORM model needs a primary key, and if you don't define one, it defaults to 'id'.

    so add:

    protected static $_primary_key = array('otherfieldname');
  • id must use by insert id in INSERT SQL and affected id in UPDATE OR DELETE SQL
  • HarroHarro
    Accepted Answer
    Not required, the ORM requires a unique primary key. That does not have to be a number, and it does not have to be an auto_increment column. But if it isn't you have to assign the value yourself before you save the object.

Howdy, Stranger!

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

In this Discussion