Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Clearing out query builder objects - new feature?
  • Well, I'm working on a project that will be using modules fairly heavily, and am trying to make module installations as simple as possible. One thing thing I'm running into now while extending Model queries from a module is changing the sort order. Here is an example
    //model
    $query = DB::select('id', 'name')->from('users')->order_by('name');
    
    //module adds a new column to select from and wants to order by something other than name without having to rebuild the query
    $query->select('order')->order_by('order');
    
    //issue is, it still take in 'name' sorting before 'order' sorting
    
    //need something to clear out the $_order_by var in the class - fully, 1 part or sections based of column name
    // or an insert_(before/after) column name to change the ordering.. something like
    $query->clear('order_by')
    
    //or
    $query->clear('order_by', 'name')
    
    //or
    $query->order_by_before('name', 'order')
    

    I will probably be working on something like this soon for my personal project. My question: is this something other people would find valuable? If so I might spend some more time on it to make a commit. If you would find this useful and have any suggestions/input.. feel free to let me know.
  • Harro Verton wrote on Tuesday 2nd of August 2011:
    The QB currently doesn't support modifications to things already set, it can only add new items. For the moment, the only solution is to extend the QB in your application (core/classes/database/query/builder/where.php) and add methods to unset things. You can add this as a feature request in the github issue tracker if you want, so we can consider this for the upcoming QB redesign.

    That was what I was talking about doing, making some functions and submitting it.. but i didn't know you were redesigning the QB, so maybe I'll just hold off and add it as a suggestion like you said.
  • I haven't really started yet, but it's on the roadmap. It is needed to properly support other SQL dialects than SQL-92, and DBMS platforms other then MySQL.
  • Couldn't you just set a variable $order_by and add to the query before you execute it? Or are you thinking of resorting it after it has been executed... You could just simply sort it with PHP...
  • Frank Bardon wrote on Monday 1st of August 2011:
    Couldn't you just set a variable $order_by and add to the query before you execute it? Or are you thinking of resorting it after it has been executed... You could just simply sort it with PHP...

    setting an $order_by var wouldn't work because the module doesn't have access to that var. Everything is done pre-execution.
  • The QB currently doesn't support modifications to things already set, it can only add new items. For the moment, the only solution is to extend the QB in your application (core/classes/database/query/builder/where.php) and add methods to unset things. You can add this as a feature request in the github issue tracker if you want, so we can consider this for the upcoming QB redesign.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion