impresspages / ImpressPages

ImpressPages is php framework with admin panel. Build functional website in one hour.
http://www.impresspages.org
Other
501 stars 178 forks source link

Ability to Join Tables. #771

Closed flakerimi closed 8 years ago

flakerimi commented 8 years ago

I have made a small change on DB class which selectAll, selectRow and selectValue can accept mysql JOINS now.

https://github.com/flakerimi/ImpressPages/blob/master/Ip/Db.php#L188 SelectAll, SelectRow, SelectValue now can join Other Tables,

Syntax is

 ipDb()->selectAll($table, $columns, $where = array(), $sqlEnd ='',$joinTable='', joinConnectField='', $joinWhere='')

Maybe better connect field would be $table.’_id’ but since it breaks current multilingual solution you have to specify it.

So now you can have User and Profile together.

 ipDb()->selectAll(‘user’, ‘*’, array(‘age’=>25), ‘ORDER BY ‘age’
ASC’,’profile’,'user_id', array(’active’=>1))

Or Select Multilanguage categories tables,


 ipDb()->selectAll(‘categories’, ‘*’, array(‘active’=>1), ‘ORDER BY
‘id’ ASC’,’categories_language’,'itemId', array(’slug’=>$slug, ‘language’ =‘en’))

You can still use ipDb()->selectAll(‘categories’, ‘*’) @jankus @maskas I tried not to break current implementation, but for 5.0 maybe we should do this as chain methods. ipDb()->selectAll($table, $columns)->where( $where = array())->join($joinTable='', joinConnectField='', $joinWhere='')->end($sqlEnd); what do you think?

maskas commented 8 years ago

Maybe. Not sure. You can use these changes on your websites without breaking the core.

You can also integrate any kind of ORM and use it's ->where ->join, etc. No need to reinvent the wheel :)

flakerimi commented 8 years ago

Yeah sure, I have this on Overrides folder of theme. I just throw this as an idea, so no strings attached.