Class AkHasMany

(line 80)

Description

AkObject
   |
   --AkObserver
      |
      --AkAssociation
         |
         --AkHasMany

Located in File: /AkActiveRecord/AkAssociations/AkHasMany.php

Adds the following methods for retrieval and query of collections of associated objects.

collection is replaced with the singular form of current association, so var $has_many = 'clients' would hold an array of objects on $this->clients and a collection handling interface instance on $this->client (singular form)

* collection->load($force_reload = false) - returns an array of all the associated objects. An empty array is returned if none are found. * collection->add($object, ?) - adds one or more objects to the collection by setting their foreign keys to the collection's primary key. (collection->push and $collection->concat are aliases to this method). * collection->delete($object, ?) - removes one or more objects from the collection by setting their foreign keys to NULL. This will also destroy the objects if they?re declared as belongs_to and dependent on this model. * collection->set($objects) - replaces the collections content by deleting and adding objects as appropriate. * collection->setByIds($ids) - replace the collection by the objects identified by the primary keys in ids * collection->clear() - removes every object from the collection. This destroys the associated objects if they are 'dependent', deletes them directly from the database if they are 'dependent' => 'delete_all', and sets their foreign keys to NULL otherwise. * collection->isEmpty() - returns true if there are no associated objects. * collection->getSize() - returns the number of associated objects. * collection->find() - finds an associated object according to the same rules as ActiveRecord->find. * collection->count() - returns the number of elements associated. (collection->size() is an alias to this method) * collection->build($attributes = array()) - returns a new object of the collection type that has been instantiated with attributes and linked to this object through a foreign key but has not yet been saved. *Note:* This only works if an associated object already exists, not if it?s null * collection->create($attributes = array()) - returns a new object of the collection 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). *Note:* This only works if an associated object already exists, not if it?s null

Example: A Firm class declares has_many clients, which will add:

* Firm->client->load() (similar to $Clients->find('all', array('conditions' => 'firm_id = '.$id)) ) * Firm->client->add() * Firm->client->delete() * Firm->client->assign() * Firm->client->assignByIds() * Firm->client->clear() * Firm->client->isEmpty() (similar to count($Firm->clients) == 0) * Firm->client->getSize() (similar to Client.count "firm_id = #{id}") * Firm->client->find() (similar to $Client->find($id, array('conditions' => 'firm_id = '.$id)) ) * Firm->client->build() (similar to new Client(array('firm_id' => $id)) ) * Firm->client->create() (similar to $c = new Client(array('firm_id' => $id)); $c->save(); return $c )

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

Options are:

* 'class_name' - specify the class name of the association. Use it only if that name can't be inferred from the association name. So "$has_many = 'products'" will by default be linked to the Product class, but if the real class name is SpecialProduct, you?ll have to specify it with this option. * 'conditions' - specify the conditions that the associated objects must meet in order to be included as a "WHERE" sql fragment, such as "price > 5 AND name LIKE ?B%?". * 'order' - specify the order in which the associated objects are returned as a "ORDER BY" sql fragment, such as "last_name, first_name DESC" * 'group' - specify the attribute by which the associated objects are returned as a "GROUP BY" sql fragment, such as "category" * 'foreign_key' - 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 has_many association will use "person_id" as the default foreign_key. * 'dependent' - if set to 'destroy' all the associated objects are destroyed alongside this object by calling their destroy method. If set to 'delete_all' all associated objects are deleted without calling their destroy method. If set to 'nullify' all associated objects? foreign keys are set to NULL without calling their save callbacks. * 'finder_sql' - specify a complete SQL statement to fetch the association. This is a good way to go for complex associations that depend on multiple tables. Note: When this option is used, findInCollection is not added. * 'counter_sql' - specify a complete SQL statement to fetch the size of the association. If +'finder_sql'+ is specified but +'counter_sql'+, +'counter_sql'+ will be generated by replacing SELECT ? FROM with SELECT COUNT(*) FROM. * 'include' - specify second-order associations that should be eager loaded when the collection is loaded. * 'group' An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. * 'limit' An integer determining the limit on the number of rows that should be returned. * 'offset' An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows. * 'select' By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not include the joined columns.

Option examples:

$has_many = array( 'comments' => array('order' => 'posted_on', 'include' => 'author', 'dependent' => 'nullify'), 'people' => array('conditions' => 'deleted = 0', 'order' => 'name'), 'tracks' => array('order' => 'position', 'dependent' => 'destroy'), 'members' => array('class_name' => 'Person', 'conditions' => 'role = "merber"'));



Class Variables

Summary:

$associated_ids = array() (line 82)

Data type : mixed

$association_id (line 83)

Data type : mixed

Class Constants

Summary:

Method Detail

Summary:
void add ( &$Associated)
void &addAssociated ( $association_id, [ $options = array()])
void addId ( $id)
void afterCreate ( &$object)
void afterUpdate ( &$object)
void beforeDestroy ( &$object)
void &build ([ $attributes = array()], [ $set_as_new_record = true])
void clear ()
void concat ( &$record)
void constructSql ([ $set_owner_table_has_included = true])
void count ([ $force_count = false])
void &create ([ $attributes = array()])
void delete ( &$Associated, [ $Skip = null])
void deleteAll ([ $Skip = null])
void &find ()
void getAssociatedFinderSqlOptions ( $association_id, [ $options = array()])
void getSize ()
void getType ()
void isEmpty ()
void &load ([ $force_reload = false])
void push ( &$record)
void removeFromCollection ( &$records)
void reset ()
void set ( &$objects)
void setByIds ()
void setIds ()
void size ()
void _afterCallback ( &$object)
void &_build ( $association_id,  &$AssociatedObject, [ $reference_associated = true])
void _getAssociatedMemberId ( &$Member)
void _hasAssociatedMember ( &$Member)
void _relateAssociatedWithOwner ( &$Associated)
void _setAssociatedMemberId ( &$Member)
void &_setCollectionHandler ( $association_id,  $handler_name)
void _unsetAssociatedMemberId ( &$Member)

Method add (line 189)

void add( &$Associated)

add($object), add(array($object, $object2)) - adds one or more objects to the collection by setting their foreign keys to the collection?s primary key. Items are saved automatically when parent has been saved.

Parameters

  • &$Associated:

Info

Method addAssociated (line 85)

void &addAssociated( $association_id, [ $options = array()])

Overrides : AkAssociation::addAssociated() Class interfaces. All Association objects must implement the following methods

Parameters

  • $association_id:
  • $options:

Info

Method addId (line 268)

void addId( $id)

Parameters

  • $id:

Info

Method afterCreate (line 674)

void afterCreate( &$object)

Triggers

Parameters

  • &$object:

Info

Method afterUpdate (line 679)

void afterUpdate( &$object)

Parameters

  • &$object:

Info

Method beforeDestroy (line 685)

void beforeDestroy( &$object)

Parameters

  • &$object:

Info

Method build (line 522)

void &build( [ $attributes = array()], [ $set_as_new_record = true])

Parameters

  • $attributes:
  • $set_as_new_record:

Info

Method clear (line 666)

void clear( )

Info

Method concat (line 224)

void concat( &$record)

Parameters

  • &$record:

Info

Method constructSql (line 459)

void constructSql( [ $set_owner_table_has_included = true])

Parameters

  • $set_owner_table_has_included:

Info

Method constructSqlForInclusion (line 575)

void constructSqlForInclusion( )

Info

Method count (line 486)

void count( [ $force_count = false])

Parameters

  • $force_count:

Info

Method create (line 534)

void &create( [ $attributes = array()])

Parameters

  • $attributes:

Info

Method delete (line 278)

void delete( &$Associated, [ $Skip = null])

Parameters

  • &$Associated:
  • $Skip:

Info

Method deleteAll (line 232)

void deleteAll( [ $Skip = null])

Remove all records from this association

Parameters

  • $Skip:

Info

Method find (line 612)

void &find( )

Info

Method getAssociatedFinderSqlOptions (line 544)

void getAssociatedFinderSqlOptions( $association_id, [ $options = array()])

Overrides : AkAssociation::getAssociatedFinderSqlOptions() parent method not documented

Parameters

  • $association_id:
  • $options:

Info

Method getAssociatedModelInstance (line 600)

void &getAssociatedModelInstance( )

Info

Method getSize (line 661)

void getSize( )

Info

Method getType (line 128)

void getType( )

Overrides : AkAssociation::getType() parent method not documented

Info

Method isEmpty (line 656)

void isEmpty( )

Info

Method load (line 158)

void &load( [ $force_reload = false])

Parameters

  • $force_reload:

Info

Method push (line 219)

void push( &$record)

Parameters

  • &$record:

Info

Method removeFromCollection (line 345)

void removeFromCollection( &$records)

Remove records from the collection. Use delete() in order to trigger database dependencies

Parameters

  • &$records:

Info

Method reset (line 238)

void reset( )

Info

Method set (line 244)

void set( &$objects)

Parameters

  • &$objects:

Info

Method setByIds (line 262)

void setByIds( )

Info

Method setIds (line 250)

void setIds( )

Info

Method size (line 516)

void size( )

Info

Method _afterCallback (line 739)

void _afterCallback( &$object)

Parameters

  • &$object:

Info

Method _build (line 442)

void &_build( $association_id, &$AssociatedObject, [ $reference_associated = true])

Overrides : AkAssociation::_build() parent method not documented

Parameters

  • $association_id:
  • &$AssociatedObject:
  • $reference_associated:

Info

Method _getAssociatedMemberId (line 413)

void _getAssociatedMemberId( &$Member)

Parameters

  • &$Member:

Info

Method _getCachedCounterAttributeName (line 594)

void _getCachedCounterAttributeName( )

Info

Method _hasAssociatedMember (line 421)

void _hasAssociatedMember( &$Member)

Parameters

  • &$Member:

Info

Method _hasCachedCounter (line 588)

void _hasCachedCounter( )

Info

Method _relateAssociatedWithOwner (line 427)

void _relateAssociatedWithOwner( &$Associated)

Parameters

  • &$Associated:

Info

Method _setAssociatedMemberId (line 395)

void _setAssociatedMemberId( &$Member)

Parameters

  • &$Member:

Info

Method _setCollectionHandler (line 133)

void &_setCollectionHandler( $association_id, $handler_name)

Parameters

  • $association_id:
  • $handler_name:

Info

Method _unsetAssociatedMemberId (line 406)

void _unsetAssociatedMemberId( &$Member)

Parameters

  • &$Member:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited From Class AkAssociation

AkAssociation::$models -

AkAssociation::$options -

AkAssociation::$Owner -

Inherited From Class AkObserver

AkObserver::$_observing - $_observing array of models that we're observing

Inherited Methods

Inherited Method Summary

Inherited From Class AkAssociation

AkAssociation::AkAssociation() -

AkAssociation::addAssociated() - Class interfaces. All Association objects must implement the following methods

AkAssociation::addModel() -

AkAssociation::getAssociatedFinderSqlOptions() -

AkAssociation::getAssociatedIds() -

AkAssociation::getModel() -

AkAssociation::getModels() -

AkAssociation::getOption() -

AkAssociation::getOptions() -

AkAssociation::getType() -

AkAssociation::initializeAssociated() -

AkAssociation::isOwnerAnActiveRecord() -

AkAssociation::loadAssociated() -

AkAssociation::setAssociatedId() -

AkAssociation::setAssociationId() -

AkAssociation::setOptions() -

AkAssociation::_build() -

AkAssociation::_findOwnerTypeForAssociation() - Recurses through $owner and its superclasses until it finds the class which defines the association to the given $associatedModel

AkAssociation::_getLoadedHandler() -

AkAssociation::_hasTablePrefix() -

AkAssociation::_saveLoadedHandler() -

AkAssociation::_setAssociationAccesorAliasReferences() -


Inherited From Class AkObserver

AkObserver::__construct() -

AkObserver::observe() - Constructs the Observer

AkObserver::setObservedModels() - Constructs the Observer

AkObserver::update() -


Inherited From Class AkObject

AkObject::AkObject() - A hack to support __construct() on PHP 4

AkObject::__construct() - Class constructor, overriden in descendant classes

AkObject::freeMemory() - Unsets circular reference children that are not freed from memory when calling unset() or when the parent object is garbage collected.

AkObject::log() -

AkObject::toString() - Object-to-string conversion

AkObject::__clone() - Clone class (Zend Engine 2 compatibility trick)

AkObject::__destruct() - Class destructor, overriden in descendant classes

AkObject::__toString() -



Documentation generated on Tue, 17 Jun 2008 14:25:34 +0200 by phpDocumentor 1.3.2