Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validate ORM Relating Models
  • Hi everyone,
    I need know how i can validate an model on relating models. For example, in:

    $comment = new Model_Comment();
    $comment->post = new Model_Post();
    $comment->save();

    How can i validate if $comment->post have a Model_Post, equal for example:

    $comment = new Model_Comment();
    $comment->date = date('Y-m-d');
    $comment->save();

    On validation function

    public static function validate($factory)    {
            $val = Validation::forge($factory);
            $val->add_field('date', 'Date', 'required|valid_date'); //I wish know this, but for validating relatin models.

            return $val;
        }
  • HarroHarro
    Accepted Answer
    That is not going to be easy, since you can't validate the underlying key because it is only assigned a value when Model_Post is saved (assuming you have cascade_save on the relation).

    Personally I would consider this a developer error, and not an input error, so I would not validate it, define the foreign key as NOT NULL, and capture the exception on save().

Howdy, Stranger!

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

In this Discussion