Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Whats the easiest way to check if object has record in many-to-many relation?
  • Kohana has something like $user->has('role', ORM::factory('role', 1)). Is there something similar here or is there another way of checking this (and not looping trough all)? TY
  • Figured it out myself!
  • For those who haven't done that: use the is_fetched() method and a count on the object.
    if ($model->relation->is_fetched() and count($model->relation))
    {
        // there are related records loaded
    }
    

    This will NOT trigger a load. If you want to trigger a load, do only the count, and the ORM will fetch the related records before counting them.

Howdy, Stranger!

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

In this Discussion