Handling Heroku/ClearDB auto Increment primary key strategy Handling Heroku/ClearDB auto Increment primary key strategy heroku heroku

Handling Heroku/ClearDB auto Increment primary key strategy


There are basically two strategies to handle that

No auto-increment

Don't use the auto-increment. Simply add the id values yourself, when inserting data. For a table like 'status', that probably contains only static data, you don't dynamically change, that might be good option.

String constants

Check for the string values. And define those strings as class constants.

class YourClass {  const ACTIVE = 'Active';  const RETIRED = 'Retired';  ...}

And then write your checks as

if($status['name'] == self::ACTIVE){  //do something}

I'd recommend to use the second approach, mostly because it makes your code more semantic. Its much easier to see what $status['name'] == self::RETIRED means than $status['id'] == 2

And if you add an index on the name column on that table there won't be (almost) any difference in performance when you query by name instead of by primary key.