⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

I need help with a query.



betojulio
  • profile picture
  • Member

Posted 08 January 2015 - 04:23 AM

Hi , I am new using grosery_crud and I like it so far.

I need some help with a more advanced query that I want to do.

My query is "select SuId,SuNombre,SuBaja,count(VeId) as 'vehiculos'

                     from sucursal join site on SuID=Sucursal_SuId

                                            join cliente on SiId=Site_SiId 

                                            join vehiculo on ClId=Cliente_ClId

                    where Mayorista_MaId="1" and SuBaja='0'

                    group by SuId "

 

how can acomplish this query using grosery_crud.

Thank you in advance.

 


Amit Shah
  • profile picture
  • Member

Posted 08 January 2015 - 06:52 AM

well joins are simply set by using set_relation

as for only count is in trouble where it cant count in directly... so u can 2 options

1 - create your own model and set the query...

2 - create a callback and give the count figuar manually


betojulio
  • profile picture
  • Member

Posted 08 January 2015 - 13:24 PM

I am having problems understanding the set_model function.

Can some one give me an easy example?

thanks.


Amit Shah
  • profile picture
  • Member

Posted 08 January 2015 - 16:24 PM

well .. using set moel have its own complexity. .. trust me - even i dont use it.. i will prefer u use callback.,,.. unless u using datatables.. then going with the model would make sense .. else with flexigrid - its absolutely no worries,


betojulio
  • profile picture
  • Member

Posted 08 January 2015 - 16:59 PM

Thank you  Amit Shah.

Wold you help creating the query using set_relation() ?

I have this

$cruds->set?relation('SuId','site','Sucursal_Suid')

which I believe is for my Mysql log " SELECT `sucursal`.*, j78ccbf7e.Sucursal_SuId AS s78ccbf7e
FROM (`sucursal`)
LEFT JOIN `site` as j78ccbf7e ON `j78ccbf7e`.`SiId` = `sucursal`.`SuId`
LIMIT 10

 

Can I have another set_relation? who do I join them ? should I better use set_relation_n_n()?

 

This is the query that I want to accomplish

"select SuId,SuNombre,SuBaja,count(VeId) as 'vehiculos'

                     from sucursal join site on SuID=Sucursal_SuId

                                            join cliente on SiId=Site_SiId 

                                            join vehiculo on ClId=Cliente_ClId

                    where Mayorista_MaId="1" and SuBaja='0'

                    group by SuId "

 

Thank you


Amit Shah
  • profile picture
  • Member

Posted 08 January 2015 - 21:27 PM

Well - yes u can have multiple set relations

the set relation in the GC works all on the primary key...

the 1st param u send is the source (current table field), the second is the table name and the 3rd is the name of the field u wana display up.

GC automatically picksup the pk of the relation table and sets it up in the query.

 

go ahead - create 3 relation and c the magic working :)