PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class TActiveRecordBelongsTo

Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between the source objects and the related foreign object. Consider the entity relationship between a Team and a Player.

+------+            +--------+
| Team | 1 <----- * | Player |
+------+            +--------+

Where one team may have 0 or more players and each player belongs to only one team. We may model Team-Player object relationship as active record as follows.

class TeamRecord extends TActiveRecord
{
    // see TActiveRecordHasMany for detailed definition.
}
class PlayerRecord extends TActiveRecord
{
    const TABLE='player';
    public $player_id; //primary key
    public $team_name; //foreign key player.team_name <-> team.name
           public $age;
    public $team; //foreign object TeamRecord

public static $RELATIONS = array
    (
                'team' => array(self::BELONGS_TO, 'TeamRecord')
    );

   public static function finder($className=__CLASS__)
   {
           return parent::finder($className);
   }
}

The static $RELATIONS property of PlayerRecord defines that the property $team belongs to a TeamRecord.

The team object may be fetched as follows.

$players = PlayerRecord::finder()->with_team()->findAll();

The method with_xxx() (where xxx is the relationship property name, in this case, team) fetchs the corresponding TeamRecords using a second query (not by using a join). The with_xxx() accepts the same arguments as other finder methods of TActiveRecord, e.g. with_team('location = ?', 'Madrid').

TActiveRecordRelation
Extended by TActiveRecordBelongsTo
Package: System\Data\ActiveRecord\Relations
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Wei Zhuo <weizho[at]gmail[dot]com>
Version: $Id$
Since: 3.1
Located at Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
Methods summary
protected
# collectForeignObjects( array & $results )

Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.

Get the foreign key index values from the results and make calls to the database to find the corresponding foreign objects.

Parameters

$results
array
original results.
public array
# getRelationForeignKeys( )

Returns

array
foreign key field names as key and object properties as value.

Since

3.1.2
protected
# setObjectProperty( TActiveRecord $source, array $properties, array & $collections )

Sets the foreign objects to the given property on the source object.

Sets the foreign objects to the given property on the source object.

Parameters

$source
TActiveRecord
source object.
$properties
array
foreign objects.
$collections
array
foreign objects.

Overrides

TActiveRecordRelation::setObjectProperty()
public boolean
# updateAssociatedRecords( )

Updates the source object first.

Updates the source object first.

Returns

boolean
true if all update are success (including if no update was required), false otherwise .
Methods inherited from TActiveRecordRelation
__call(), __construct(), fetchResultsInto(), findForeignKeys(), findForeignObjects(), getContext(), getCriteria(), getIndexValues(), getObjectHash(), getSourceRecord(), populateResult(), setResultCollection()
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO