Hello,
NotORM is having a strange behavior with this particular request:
$models = $this->dbh->wh_product()->select("wh_product.id, wh_model.id, wh_model.manufacturer, wh_model.model, wh_model.details, wh_model.wh_category.category, crm_contact.ragione")->group("crm_contact_id, wh_model_id")->order("wh_model.wh_category.id ASC, crm_contact.ragione ASC, wh_model.model ASC");
If I printf the NotORM object I get this query:
SELECT wh_model.id, wh_model.manufacturer, wh_model.model, wh_model.details, wh_category.category, crm_contact.ragione
FROM wh_product
LEFT JOIN wh_model ON wh_product.wh_model_id = wh_model.id
LEFT JOIN wh_category ON wh_model.wh_category_id = wh_category.id
LEFT JOIN crm_contact ON wh_product.crm_contact_id = crm_contact.id
GROUP BY wh_model_id, crm_contact_id
ORDER BY wh_category.id ASC , crm_contact.ragione ASC , wh_model.model ASC
If I execute this query manually via phpmyadmin I get something like 90 results, but NotORM only gives me 14 results, which correspond to the result of this query (notice the grouping by wh_model_id alone):
SELECT wh_model.id, wh_model.manufacturer, wh_model.model, wh_model.details, wh_category.category, crm_contact.ragione
FROM wh_product
LEFT JOIN wh_model ON wh_product.wh_model_id = wh_model.id
LEFT JOIN wh_category ON wh_model.wh_category_id = wh_category.id
LEFT JOIN crm_contact ON wh_product.crm_contact_id = crm_contact.id
GROUP BY wh_model_id
ORDER BY wh_category.id ASC , crm_contact.ragione ASC , wh_model.model ASC
The same happens even without the GROUP BY condition.
FYK this is the structure of the 3 tables involved:
wh_product
id | internal_id | crm_contact_id | wh_model_id | buy_date | wh_status_id
wh_model
id | wh_category_id | manufacturer | model | details
crm_contact
id | cognome | nome | ragione
I'm trying to understand how and why this is happening but I can't sort this out.