Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
\Orm\Query::group_by() ?
  • Hi, I'm currently working on two related models 'Person' and 'Company'. I want to find all the companies which have hired persons with specifics skills. The query I want to build is something like :
    $query = Model_Company::find()->related('persons')->where('persons.p_skills', specific)->rows_limit(10)->get(); I should get all the companies related to at least one person with the specific skill.
    I only get one result to this query (I can assure you that I should have more than one line). I'm not sure about the reason I get this result, but as far as I only want to find different companies, it could come to an end with a group_by(), which actually does not exist... I was wondering why? Is there any other way of doing it? Thanks in advance!
  • This question has been asked and answered a few days ago. The ORM is not a query builder. If you use a group_by(), you end up with results that do not map directly to data objects (i.e. table rows). Run a normal DB query for this.
  • Thanks for replying so fast. I'm sorry I did not find the topic you mention, I probably did not use the right keywords. I understand the issue, I was just wondering how to deal with the query result: I guess I'll have to transform the resulting "lines" into objects afterward. Thanks again.
  • When running a standard DB query you can automatically create model objects as a result by using the as_object() method. See http://docs.fuelphp.com/classes/database/usage.html#/results

Howdy, Stranger!

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

In this Discussion