Closed mskocik closed 2 years ago
It would be great to specify some examples when QueryBuilder has to be extended. Either creating a system solution or using composition over inheritance are usually the preferable ways.
My typical use case is for usage in conjunction with Nextras\Orm
and Contributte\DataGrid
.
And for example when I needed QB with UNION
support. I had 2 options:
ICollection
, because DbalCollection
expects QueryBuilder
instanceQueryBuilder
and make parent class completely overriden, which isn't really nice.Please be more specific, ideally provide your code. I do not want to make everything protected without any understatement.
cc @mskocik
Please be more specific, ideally provide your code. I do not want to make everything protected without any understatement.
Here is the link to code diff between QB and extended QB. As you can see I am mainly overriding getSqlForSelect()
method and I need to access $args
property.
Is the QB class code enough, or shall I provide more context?
I'd rather see what you need to do then how you solved it. I can imagine having totally different class that joins two QueryBuilders and proxies call to them.
My use case:
I have some tables, for which I store changes in separate history table, always named <table>_history
.
I have grid (using ublaboo/datagrid) which shows data of all these history tables (changes) in one place. This allows me to see all changes chronologically. I can "filter on/off" which history tables (context) I am interested in. Let's say by default I show tables A
, B
, C
, D
. But I can set it to show just records from tables B
and D
. Records are always ordered by datetime
across tables.
So basically I need to apply where
per table, union them together and order by datetime
globally. So in QB among other things need access to $where
property and rewrite how SELECT query is generated based on how many unions I have there.
Due to properties and internal methods marked as private, child class need to copy-paste basically whole class. It would be great if all private properties and method will be changed to protected.