NotORM is grouping result set

67 views
Skip to first unread message

mrteo

unread,
Apr 20, 2016, 1:26:54 PM4/20/16
to NotORM
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.

Allysson David

unread,
Apr 20, 2016, 6:22:54 PM4/20/16
to not...@googlegroups.com
Hi,

Can I get the structure for wh_category?

--
You received this message because you are subscribed to the Google Groups "NotORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to notorm+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Allysson David

unread,
Apr 20, 2016, 6:58:56 PM4/20/16
to not...@googlegroups.com
I tried with the following structure:
wh_category
id | category

Could not replicate the problem. Had same number of results on both the phpmyadmin and notorm.

What is the database you're using? MySQL? 
Could you export and share the data from those four tables so we can try to replicate the problem?

Reply all
Reply to author
Forward
0 new messages