[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/AkActiveRecord/AkAssociations/ -> AkHasOne.php (summary)

(no description)

Author: Bermi Ferrer
Copyright: Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
License: GNU Lesser General Public License
File Size: 346 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 AkActiveRecord/AkAssociation.php

Defines 1 class

AkHasOne:: (14 methods):
  addAssociated()
  assign()
  getAssociatedId()
  getType()
  getAssociatedFinderSqlOptions()
  constructSqlForInclusion()
  build()
  create()
  replace()
  findAssociated()
  constructSqlConditions()
  constructSql()
  afterSave()
  afterDestroy()


Class: AkHasOne  - X-Ref

Adds the following methods for retrieval and query of a single associated object.
$association is replaced with the symbol passed as the first argument, so
<tt>hasOne('manager')</tt> would add among others <tt>$this->manager->getAttributes()</tt>.

Example: An Account class declares <tt>hasOne('beneficiary');</tt>, which will add:
* <tt>$Account->beneficiary->load()</tt> (similar to <tt>$Beneficiary->find('first', array('conditions' => "account_id = $id"))</tt>)
* <tt>$Account->beneficiary->assign($Beneficiary);</tt> (similar to <tt>$Beneficiary->account_id = $Account->id; $Beneficiary->save()</tt>)
* <tt>$Account->beneficiary->build();</tt> (similar to <tt>$Beneficiary = new Beneficiary("account_id->", $Account->id)</tt>)
* <tt>$Account->beneficiary->create();</tt> (similar to <tt>$b = new Beneficiary("account_id->", $Account->id); $b->save(); $b</tt>)

The declaration can also include an options array to specialize the behavior of the association.

Options are:
* <tt>class_name</tt>  - specify the class name of the association. Use it only if that name can't be inferred
from the association name. So <tt>hasOne('manager')</tt> will by default be linked to the "Manager" class, but
if the real class name is "Person", you'll have to specify it with this option.
* <tt>conditions</tt>  - specify the conditions that the associated object must meet in order to be included as a "WHERE"
sql fragment, such as "rank = 5".
* <tt>order</tt>       - specify the order from which the associated object will be picked at the top. Specified as
an "ORDER BY" sql fragment, such as "last_name, first_name DESC"
* <tt>dependent</tt>   - if set to true, the associated object is destroyed when this object is. It's also destroyed if another
association is assigned.
* <tt>foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name
of this class in lower-case and "_id" suffixed. So a "Person" class that makes a hasOne association will use "person_id"
as the default foreign_key.

Option examples:
var $hasOne = array(
'credit_card' => array('dependent' => true),
'last_comment' => array('class_name' => "Comment", 'order' => "posted_on"),
'project_manager' => array('class_name' => "Person", 'conditions' => "role = 'project_manager'")
);
addAssociated($association_id, $options = array()   X-Ref
No description

assign($association_id, &$Associated)   X-Ref
Assigns the associate object, extracts the primary key, sets it as the foreign key, and saves the associate object.


getAssociatedId($association_id)   X-Ref
No description

getType()   X-Ref
No description

getAssociatedFinderSqlOptions($association_id, $options = array()   X-Ref
No description

constructSqlForInclusion($association_id)   X-Ref
No description

build($association_id, $attributes = array()   X-Ref
No description

create($association_id, $attributes = array()   X-Ref
Returns a new object of the associated type that has been instantiated with attributes
and linked to this object through a foreign key and that has already been
saved (if it passed the validation)


replace($association_id, &$NewAssociated, $dont_save = false)   X-Ref
No description

findAssociated($association_id)   X-Ref
No description

constructSqlConditions($association_id)   X-Ref
No description

constructSql($association_id)   X-Ref
No description

afterSave(&$object)   X-Ref
Triggers


afterDestroy(&$object)   X-Ref
No description



Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6