Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM relation returns array, where condition
  • Hi! I have a problem again. I want to fetch data from a has_many relation (which in turn my belongs_to prod):
    $this->prod= Model_Prod::find("first", array(
    'where' => array('prod_id' => $this->id),
    'related' => array(
    'group',
    'brand',
    'dep',
    'my' => array(
    'where' => array('my.price' => 25641)
    )
    )
    )
    ); The first problem is: in my relation I can't use where like this:
    "where" => array('my.price', '>', '0') The second:
    $this->prod->my returns array.
    How can I set it to return an object? Thanks
  • Thanks for your reply.
    I should have known this. :D
  • Afaik relations are always an array of objects, even if there is only one object. That is the same with all find and get operations (except the find that explicitly returns 1 result, like first, last or "primary_key").
  • There's 2 types of relation: singular and plural. Singular relations like Has-One & Belongs-To will always return a single object or null. Plural relationships like Has-Many and Many-Many (has-and-belongs-to-many) will always return arrays even if there's one or none. That way you can always be sure an array is returned which is far preferable to a random output type which you always have to check before working with it.

Howdy, Stranger!

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

In this Discussion