Hi everybody,
ran into a problem when using the crud, my model looks like this:
class Model_Crud_Mcms_Placeholder extends \Fuel\Core\Model_Crud
{
protected static $_properties = array(
'name',
'example'
);
protected static $_table_name = 'Placeholder';
protected static $_primary_key = 'name';
protected static $_rules = array(
'name' => 'max_length[255]',
'example' => 'max_length[255]'
);
}
When I save the content to the DB the crud base think it's an autoincrement and puts the value 0 into the name column, is there a way to configure the crud in order to avoid the last insert id to be put to the primary key column?
Thanks for the help
Both Model_Crud and ORM expect the primary key to be defined as INT AUTO_INCREMENT.
If you have defined it differently, you will have to make sure the column contains a valid key value before you save the record.
Thanks for the update. Guess I will have to find another way to deal with it. When I do my update I do following:
$m = Model_Crud_Mcms_Placeholder ();
$m->name = "test_name";
$m->example = "this is the example";
$m->save();
echo $m->name; // prints: 0, expected: test_name
if somebody else runs into this problem a possible workaround is to extend the save method, I added following to my crud model:
public function save($validate = true)
{
$name = $this->name;
$ret_val = parent::save($validate);
$this->name = $name ;
return $ret_val;
}
If you have a field to which you assign a value, and this value is gone after save, that would classify as a bug.
Can you create an issue for this at http://github.com/fuel/core/issues so it can be fixed?