Custom model in custom module
Hello guys
I'm developing my first application with FuelCMS and i have a question about the models, i have read all the module related tutorials but i couldn't find what I'm looking for.
I have a database table called Categories, it has tree fields
| ID | NAME | PARENT |
The parent field is a reference to the same table and allow to nest the categories. When a category is a base one, (it has no parent) i need to insert in the database the value "-1"
For now i have my models working right but in the form it generates i can only choose between the values that already exists, I was able to hard code a new value into the option list, but i don't know how to tell Fuel that if you select the "nothing" value it have to assign -1 in the DB.
I hope it is clear
Thanks in advanced for your help.
Comments
this is my hook:
function on_before_insert($values)
{
if($values['parent']=="")
{
$values['parent'] = -1;
}
}