Changeset 1287

Show
Ignore:
Timestamp:
04/26/09 11:32:27 (1 year ago)
Author:
arnoschn
Message:

fixing a stupid Ak::compat() call.

= adding a $optionswrap? to finders.

Works as follows:

$optionswrap? = 'SELECT * FROM ({query}) a GROUP BY something";

the generated finder query is inserted for {query}.

SELECT * FROM (SELECT * FROM ... WHERE ...) a GROUP BY something";

this allows you to do group bys and still define the order of a date for example.

= added join-table columns to habtm sql generation, so you can use it in the "wrap" sql.

useful if you have information on the join class and you want to buildl conditions on that.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActiveRecord.php

    r1286 r1287  
    11<?php 
    2 Ak::compat('stripos'); 
     2 
    33/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
    44 
     
    965965        }else{ 
    966966            $sql = $this->constructFinderSql($options); 
     967            if (isset($options['wrap'])) { 
     968                $sql = str_replace('{query}',$sql,$options['wrap']); 
     969            } 
    967970            if(!empty($options['bind']) && is_array($options['bind']) && strstr($sql,'?')){ 
    968971                $sql = array_merge(array($sql),$options['bind']); 
     
    10021005                    $options['conditions'] = $table_name.'.'.$this->getPrimaryKey().' = '.$ids[0].(empty($conditions)?'':' AND '.$conditions); 
    10031006                } else { 
     1007                    Ak::compat('stripos'); 
    10041008                    if (false!==($pos=stripos($conditions,' WHERE '))) { 
    10051009                        $before_where = substr($conditions,0, $pos); 
     
    10241028                    $options['conditions'] = $ids_condition.(empty($conditions)?'':' AND '.$conditions); 
    10251029                } else { 
     1030                    Ak::compat('stripos'); 
    10261031                    if (false!==($pos=stripos($conditions,' WHERE '))) { 
    10271032                        $before_where = substr($conditions,0, $pos); 
     
    10541059            return false; 
    10551060        } 
    1056         $valid_keys = array('conditions', 'include', 'joins', 'limit', 'offset', 'group', 'order', 'sort', 'bind', 'select','select_prefix', 'readonly'); 
     1061        $valid_keys = array('wrap','conditions', 'include', 'joins', 'limit', 'offset', 'group', 'order', 'sort', 'bind', 'select','select_prefix', 'readonly'); 
    10571062        foreach (array_keys($options) as $key){ 
    10581063            if (!in_array($key,$valid_keys)){ 
     
    14111416                } 
    14121417            } else { 
     1418                Ak::compat('stripos'); 
    14131419                if (($wherePos=stripos($sql,'WHERE'))!==false) { 
    14141420                    if (!empty($type_condition)) { 
  • trunk/lib/AkActiveRecord/AkAssociatedActiveRecord.php

    r1286 r1287  
    239239        $result = false; 
    240240        $options ['include'] = Ak::toArray($options ['include']); 
    241  
     241         
    242242        $included_associations = array (); 
    243243        $included_association_options = array (); 
     
    343343         
    344344        $sql = preg_replace('/,\s*,/',' , ',$sql); 
    345  
     345         
     346        if (isset($options['wrap'])) { 
     347            $sql = str_replace('{query}',$sql,$options['wrap']); 
     348        } 
     349         
    346350        if (! empty($options ['bind']) && is_array($options ['bind']) && strstr($sql, '?')) { 
    347351            $sql = array_merge(array ($sql ), $options ['bind']); 
  • trunk/lib/AkActiveRecord/AkAssociations/AkHasAndBelongsToMany.php

    r1286 r1287  
    782782        } 
    783783 
     784         
     785        $join_class = $association_options['join_class_name']; 
     786        Ak::import($join_class); 
     787        $join_obj = new $join_class; 
     788        $join_class_columns = array_keys($join_obj->getColumns()); 
     789        foreach ($join_class_columns as $column_name){ 
     790            $finder_options['selection'] .= $parent_handler_name.'__'.$handler_name.'__'.$join_class.'.'.$column_name.' AS '.$selection_parenthesis.$prefix.'['.$handler_name.']'.($pluralize?'[@'.$pk.']':'').'['.$join_class.']['.$column_name.']'.$selection_parenthesis.', '; 
     791        } 
     792         
    784793        $finder_options['selection'] = trim($finder_options['selection'], ', '); 
    785794