root

Changeset 753

Show
Ignore:
Timestamp:
03/03/10 13:45:21 (5 months ago)
Author:
wbond
Message:

Added the ability to associate a single record via primary key in fORMRelated

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fORMRelated.php

    r745 r753 Hide Line Numbers
    66 * constraints. 
    77 *  
    8  * @copyright  Copyright (c) 2007-2009 Will Bond 
     8 * @copyright  Copyright (c) 2007-2010 Will Bond 
    99 * @author     Will Bond [wb] <will@flourishlib.com> 
    1010 * @license    http://flourishlib.com/license 
     
    1313 * @link       http://flourishlib.com/fORMRelated 
    1414 *  
    15  * @version    1.0.0b23 
     15 * @version    1.0.0b24 
     16 * @changes    1.0.0b24  Added the ability to associate a single record via primary key [wb, 2010-03-03] 
    1617 * @changes    1.0.0b23  Fixed a column aliasing issue with SQLite [wb, 2010-01-25] 
    1718 * @changes    1.0.0b22  Fixed a bug with associating a non-contiguous array of fActiveRecord objects [wb, 2009-12-17] 
     
    104105        $related_table = fORM::tablize($related_class); 
    105106         
    106         if (!$record instanceof fActiveRecord) { 
    107             $record = new $related_class($record);   
     107        if ($record !== NULL) { 
     108            if (!$record instanceof fActiveRecord) { 
     109                $record = new $related_class($record);   
     110            } 
     111            $records = array($record); 
     112        } else { 
     113            $records = array(); 
    108114        } 
    109115         
    110116        $schema  = fORMSchema::retrieve($class); 
    111         $records = fRecordSet::buildFromArray($related_class, array($record));  
     117        $records = fRecordSet::buildFromArray($related_class, $records); 
    112118        $route   = fORMSchema::getRouteName($schema, $table, $related_table, $route, 'one-to-one'); 
    113119         
     
    897903             
    898904            foreach ($routes as $route) { 
    899                 $route_names[] = fORMSchema::getRouteNameFromRelationship('one-to-one', $route); 
     905                $route_names[] = fORMSchema::getRouteNameFromRelationship('*-to-one', $route); 
    900906            } 
    901907             
     
    16281634 
    16291635/** 
    1630  * Copyright (c) 2007-2009 Will Bond <will@flourishlib.com> 
     1636 * Copyright (c) 2007-2010 Will Bond <will@flourishlib.com> 
    16311637 *  
    16321638 * Permission is hereby granted, free of charge, to any person obtaining a copy