Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Custom model in custom module

edited February 2011 in Modules
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

  • edited February 2011
    I have tried to use a hook but when i make the modifications over the value the record is never inserted, i guest it is because parent is a foreing key of the ame table si it can't insert a value that don't exists (in the database the field is NOT a foreign key, it is only at hte model)... Could it be like this?

    this is my hook:

    function on_before_insert($values)
    {
    if($values['parent']=="")
    {
    $values['parent'] = -1;
    }
    }
  • edited 11:53AM
    Try using the on_before_validate hook which should occur before any validation takes place.
  • edited 11:53AM
    Now is working with the on_before_validate hook, thanks so much :)
Sign In or Register to comment.