Mage_Core_Model_Mysql4_Abstract Class Reference

Inheritance diagram for Mage_Core_Model_Mysql4_Abstract:

Mage_Core_Model_Resource_Abstract Mage_Admin_Model_Mysql4_Role Mage_Admin_Model_Mysql4_Roles Mage_Admin_Model_Mysql4_Rules Mage_Admin_Model_Mysql4_User Mage_AdminNotification_Model_Mysql4_Inbox Mage_AmazonPayments_Model_Mysql4_Api_Debug Mage_Api_Model_Mysql4_Acl Mage_Api_Model_Mysql4_Acl_Role Mage_Api_Model_Mysql4_Role Mage_Api_Model_Mysql4_Roles Mage_Api_Model_Mysql4_Rules Mage_Api_Model_Mysql4_User Mage_Bundle_Model_Mysql4_Option Mage_Bundle_Model_Mysql4_Price_Index Mage_Bundle_Model_Mysql4_Selection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat Mage_Catalog_Model_Resource_Eav_Mysql4_Config Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Tierprice Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat_Indexer Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Status Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Website Mage_Catalog_Model_Resource_Eav_Mysql4_Sendfriend Mage_Catalog_Model_Resource_Eav_Mysql4_Url Mage_CatalogIndex_Model_Mysql4_Abstract Mage_CatalogIndex_Model_Mysql4_Aggregation Mage_CatalogIndex_Model_Mysql4_Data_Abstract Mage_CatalogIndex_Model_Mysql4_Indexer Mage_CatalogIndex_Model_Mysql4_Indexer_Abstract Mage_CatalogIndex_Model_Mysql4_Retreiver Mage_CatalogInventory_Model_Mysql4_Stock Mage_CatalogInventory_Model_Mysql4_Stock_Item Mage_CatalogInventory_Model_Mysql4_Stock_Status Mage_CatalogRule_Model_Mysql4_Rule Mage_CatalogRule_Model_Mysql4_Rule_Product_Price Mage_CatalogSearch_Model_Mysql4_Fulltext Mage_CatalogSearch_Model_Mysql4_Query Mage_Checkout_Model_Mysql4_Agreement Mage_Checkout_Model_Mysql4_Cart Mage_Cms_Model_Mysql4_Block Mage_Cms_Model_Mysql4_Page Mage_Core_Model_Mysql4_Config Mage_Core_Model_Mysql4_Config_Data Mage_Core_Model_Mysql4_Convert_History Mage_Core_Model_Mysql4_Convert_Profile Mage_Core_Model_Mysql4_Design Mage_Core_Model_Mysql4_Flag Mage_Core_Model_Mysql4_Language Mage_Core_Model_Mysql4_Layout Mage_Core_Model_Mysql4_Store Mage_Core_Model_Mysql4_Store_Group Mage_Core_Model_Mysql4_Translate Mage_Core_Model_Mysql4_Translate_String Mage_Core_Model_Mysql4_Url_Rewrite Mage_Core_Model_Mysql4_Website Mage_Cron_Model_Mysql4_Schedule Mage_Customer_Model_Entity_Group Mage_Dataflow_Model_Mysql4_Batch Mage_Dataflow_Model_Mysql4_Batch_Abstract Mage_Dataflow_Model_Mysql4_Import Mage_Dataflow_Model_Mysql4_Profile Mage_Dataflow_Model_Mysql4_Profile_History Mage_Dataflow_Model_Mysql4_Session Mage_Directory_Model_Mysql4_Country Mage_Directory_Model_Mysql4_Country_Format Mage_Directory_Model_Mysql4_Currency Mage_Downloadable_Model_Mysql4_Link Mage_Downloadable_Model_Mysql4_Link_Purchased Mage_Downloadable_Model_Mysql4_Link_Purchased_Item Mage_Downloadable_Model_Mysql4_Sample Mage_Eav_Model_Mysql4_Config Mage_Eav_Model_Mysql4_Entity_Attribute Mage_Eav_Model_Mysql4_Entity_Attribute_Group Mage_Eav_Model_Mysql4_Entity_Attribute_Option Mage_Eav_Model_Mysql4_Entity_Attribute_Set Mage_Eav_Model_Mysql4_Entity_Store Mage_Eav_Model_Mysql4_Entity_Type Mage_GiftMessage_Model_Mysql4_Message Mage_GiftRegistry_Model_Mysql4_Gift Mage_GoogleBase_Model_Mysql4_Attribute Mage_GoogleBase_Model_Mysql4_Item Mage_GoogleBase_Model_Mysql4_Type Mage_GoogleCheckout_Model_Mysql4_Api_Debug Mage_GoogleCheckout_Model_Mysql4_Tax Mage_GoogleOptimizer_Model_Mysql4_Code Mage_Log_Model_Mysql4_Aggregation Mage_Log_Model_Mysql4_Log Mage_Log_Model_Mysql4_Visitor Mage_Log_Model_Mysql4_Visitor_Online Mage_Newsletter_Model_Mysql4_Problem Mage_Newsletter_Model_Mysql4_Queue Mage_Newsletter_Model_Mysql4_Template Mage_Paygate_Model_Mysql4_Authorizenet_Debug Mage_Paypal_Model_Mysql4_Api_Debug Mage_PaypalUk_Model_Mysql4_Api_Debug Mage_Poll_Model_Mysql4_Poll Mage_Poll_Model_Mysql4_Poll_Answer Mage_Poll_Model_Mysql4_Poll_Vote Mage_ProductAlert_Model_Mysql4_Price Mage_ProductAlert_Model_Mysql4_Stock Mage_Rating_Model_Mysql4_Rating Mage_Rating_Model_Mysql4_Rating_Entity Mage_Rating_Model_Mysql4_Rating_Option_Vote Mage_Reports_Model_Mysql4_Event Mage_Reports_Model_Mysql4_Event_Type Mage_Review_Model_Mysql4_Review Mage_Review_Model_Mysql4_Review_Summary Mage_Rule_Model_Mysql4_Rule Mage_Sales_Model_Mysql4_Abstract Mage_Sales_Model_Mysql4_Order_Tax Mage_Sales_Model_Mysql4_Quote_Item_Option Mage_SalesRule_Model_Mysql4_Rule Mage_SalesRule_Model_Mysql4_Rule_Customer Mage_SalesRule_Model_Mysql4_Rule_Product Mage_Sendfriend_Model_Mysql4_Sendfriend Mage_Shipping_Model_Mysql4_Carrier_Tablerate Mage_Sitemap_Model_Mysql4_Catalog_Category Mage_Sitemap_Model_Mysql4_Catalog_Product Mage_Sitemap_Model_Mysql4_Cms_Page Mage_Sitemap_Model_Mysql4_Sitemap Mage_Tag_Model_Mysql4_Tag Mage_Tag_Model_Mysql4_Tag_Relation Mage_Tax_Model_Mysql4_Calculation Mage_Tax_Model_Mysql4_Calculation_Rate Mage_Tax_Model_Mysql4_Calculation_Rate_Title Mage_Tax_Model_Mysql4_Calculation_Rule Mage_Tax_Model_Mysql4_Class Mage_Weee_Model_Mysql4_Attribute_Backend_Weee_Tax Mage_Weee_Model_Mysql4_Tax Mage_Wishlist_Model_Mysql4_Item Mage_Wishlist_Model_Mysql4_Wishlist

List of all members.

Public Member Functions

 getIdFieldName ()
 getMainTable ()
 getTable ($entityName)
 getReadConnection ()
 load (Mage_Core_Model_Abstract $object, $value, $field=null)
 save (Mage_Core_Model_Abstract $object)
 delete (Mage_Core_Model_Abstract $object)
 addUniqueField ($field)
 resetUniqueField ()
 getUniqueFields ()
 afterLoad (Mage_Core_Model_Abstract $object)
 getChecksum ($table)

Public Attributes

const CHECKSUM_KEY_NAME = 'Checksum'

Protected Member Functions

 _init ($mainTable, $idFieldName)
 _setResource ($connections, $tables=null)
 _setMainTable ($mainTable, $idFieldName=null)
 _getConnection ($connectionName)
 _getReadAdapter ()
 _getWriteAdapter ()
 _getLoadSelect ($field, $value, $object)
 _initUniqueFields ()
 _prepareDataForSave (Mage_Core_Model_Abstract $object)
 _prepareValueForSave ($value, $type)
 _checkUnique (Mage_Core_Model_Abstract $object)
 _afterLoad (Mage_Core_Model_Abstract $object)
 _beforeSave (Mage_Core_Model_Abstract $object)
 _afterSave (Mage_Core_Model_Abstract $object)
 _beforeDelete (Mage_Core_Model_Abstract $object)
 _afterDelete (Mage_Core_Model_Abstract $object)

Protected Attributes

 $_resources
 $_resourcePrefix
 $_connections = array()
 $_resourceModel
 $_tables = array()
 $_mainTable
 $_idFieldName
 $_isPkAutoIncrement = true
 $_mainTableFields
 $_uniqueFields = null


Detailed Description

Definition at line 36 of file Abstract.php.


Member Function Documentation

_afterDelete ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions after object delete

Parameters:
Varien_Object $object

Reimplemented in Mage_Admin_Model_Mysql4_Roles, Mage_Api_Model_Mysql4_Roles, Mage_Bundle_Model_Mysql4_Option, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Website, Mage_Customer_Model_Entity_Group, and Mage_Review_Model_Mysql4_Review.

Definition at line 597 of file Abstract.php.

00598     {
00599         return $this;
00600     }

_afterLoad ( Mage_Core_Model_Abstract object  )  [protected]

_afterSave ( Mage_Core_Model_Abstract object  )  [protected]

_beforeDelete ( Mage_Core_Model_Abstract object  )  [protected]

Perform actions before object delete

Parameters:
Varien_Object $object

Reimplemented in Mage_Customer_Model_Entity_Group, and Mage_Review_Model_Mysql4_Review.

Definition at line 587 of file Abstract.php.

00588     {
00589         return $this;
00590     }

_beforeSave ( Mage_Core_Model_Abstract object  )  [protected]

_checkUnique ( Mage_Core_Model_Abstract object  )  [protected]

Check for unique values existence

Parameters:
Varien_Object $object
Returns:
Mage_Core_Model_Mysql4_Abstract
Exceptions:
Mage_Core_Exception 

Definition at line 496 of file Abstract.php.

00497     {
00498         $existent = array();
00499         $fields = $this->getUniqueFields();
00500         if (!empty($fields)) {
00501             if (!is_array($fields)) {
00502                 $this->_uniqueFields = array(
00503                     array(
00504                         'field' => $fields,
00505                         'title' => $fields
00506                 ));
00507             }
00508 
00509             $data = new Varien_Object($this->_prepareDataForSave($object));
00510             $select = $this->_getWriteAdapter()->select()
00511                 ->from($this->getMainTable());
00512 
00513             foreach ($fields as $unique) {
00514                 $select->reset(Zend_Db_Select::WHERE);
00515 
00516                 if (is_array($unique['field'])) {
00517                     foreach ($unique['field'] as $field) {
00518                         $select->where($field.'=?', $data->getData($field));
00519                     }
00520                 }
00521                 else {
00522                     $select->where( $unique['field'] . ' = ?', $data->getData($unique['field']) );
00523                 }
00524 
00525                 if ($object->getId()) {
00526                     $select->where($this->getIdFieldName().' != ?', $object->getId());
00527                 }
00528 
00529                 if ( $test = $this->_getWriteAdapter()->fetchRow($select) ) {
00530                     $existent[] = $unique['title'];
00531                 }
00532             }
00533         }
00534 
00535         if (!empty($existent)) {
00536             if (count($existent) == 1 ) {
00537                 $error = Mage::helper('core')->__('%s already exist', $existent[0]);
00538             }
00539             else {
00540                 $error = Mage::helper('core')->__('%s already exists', implode(', ', $existent));
00541             }
00542             Mage::throwException($error);
00543         }
00544         return $this;
00545     }

_getConnection ( connectionName  )  [protected]

Get connection by name or type

Parameters:
string $connectionName
Returns:
Zend_Db_Adapter_Abstract

Definition at line 248 of file Abstract.php.

00249     {
00250         if (isset($this->_connections[$connectionName])) {
00251             return $this->_connections[$connectionName];
00252         }
00253         if (!empty($this->_resourcePrefix)) {
00254             $this->_connections[$connectionName] = $this->_resources->getConnection(
00255                 $this->_resourcePrefix.'_'.$connectionName);
00256         } else {
00257             $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName);
00258         }
00259 
00260         return $this->_connections[$connectionName];
00261     }

_getLoadSelect ( field,
value,
object 
) [protected]

Retrieve select object for load object data

Parameters:
string $field
mixed $value
Returns:
Zend_Db_Select

Reimplemented in Mage_CatalogInventory_Model_Mysql4_Stock_Item, Mage_CatalogSearch_Model_Mysql4_Query, Mage_Checkout_Model_Mysql4_Agreement, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Translate_String, Mage_Core_Model_Mysql4_Url_Rewrite, Mage_Rating_Model_Mysql4_Rating, Mage_Review_Model_Mysql4_Review_Summary, Mage_Review_Model_Mysql4_Review, and Mage_Sales_Model_Mysql4_Quote.

Definition at line 329 of file Abstract.php.

00330     {
00331            $select = $this->_getReadAdapter()->select()
00332             ->from($this->getMainTable())
00333             ->where($this->getMainTable().'.'.$field.'=?', $value);
00334         return $select;
00335     }

_getReadAdapter (  )  [protected]

Retrieve connection for read data

Returns:
Zend_Db_Adapter_Abstract

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 268 of file Abstract.php.

00269     {
00270         return $this->_getConnection('read');
00271     }

_getWriteAdapter (  )  [protected]

Retrieve connection for write data

Returns:
Zend_Db_Adapter_Abstract

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 278 of file Abstract.php.

00279     {
00280         return $this->_getConnection('write');
00281     }

_init ( mainTable,
idFieldName 
) [protected]

Standard resource model initialization

Parameters:
string $mainTable
string $idFieldName
Returns:
Mage_Core_Model_Mysql4_Abstract

Definition at line 124 of file Abstract.php.

00125     {
00126         $this->_setMainTable($mainTable, $idFieldName);
00127     }

_initUniqueFields (  )  [protected]

_prepareDataForSave ( Mage_Core_Model_Abstract object  )  [protected]

Prepare data for save

Parameters:
Mage_Core_Model_Abstract $object
Returns:
array

Reimplemented in Mage_Log_Model_Mysql4_Visitor, and Mage_Sales_Model_Mysql4_Abstract.

Definition at line 451 of file Abstract.php.

00452     {
00453         $data = array();
00454         $fields = $this->_getWriteAdapter()->describeTable($this->getMainTable());
00455         foreach (array_keys($fields) as $field) {
00456             if ($object->hasData($field)) {
00457                 $fieldValue = $object->getData($field);
00458                 if ($fieldValue instanceof Zend_Db_Expr) {
00459                     $data[$field] = $fieldValue;
00460                 }
00461                 else {
00462                     if (null !== $fieldValue) {
00463                         $data[$field] = $this->_prepareValueForSave($fieldValue, $fields[$field]['DATA_TYPE']);
00464                     }
00465                     elseif (!empty($fields[$field]['NULLABLE'])) {
00466                         $data[$field] = null;
00467                     }
00468                 }
00469             }
00470         }
00471         return $data;
00472     }

_prepareValueForSave ( value,
type 
) [protected]

Prepare value for save

Parameters:
mixed $value
string $type
Returns:
mixed

Definition at line 481 of file Abstract.php.

00482     {
00483         if ($type == 'decimal') {
00484             $value = Mage::app()->getLocale()->getNumber($value);
00485         }
00486         return $value;
00487     }

_setMainTable ( mainTable,
idFieldName = null 
) [protected]

Set main entity table name and primary key field name

If field name is ommited {table_name}_id will be used

Parameters:
string $mainTable
string|null $idFieldName
Returns:
Mage_Core_Model_Mysql4_Abstract

Definition at line 175 of file Abstract.php.

00176     {
00177         $mainTableArr = explode('/', $mainTable);
00178 
00179         if (!empty($mainTableArr[1])) {
00180             if (empty($this->_resourceModel)) {
00181                 $this->_setResource($mainTableArr[0]);
00182             }
00183             $this->_setMainTable($mainTableArr[1], $idFieldName);
00184         } else {
00185             $this->_mainTable = $mainTable;
00186             if (is_null($idFieldName)) {
00187                 $idFieldName = $mainTable.'_id';
00188             }
00189             $this->_idFieldName = $idFieldName;
00190         }
00191 
00192         return $this;
00193     }

_setResource ( connections,
tables = null 
) [protected]

Initialize connections and tables for this resource model

If one or both arguments are string, will be used as prefix If $tables is null and $connections is string, $tables will be the same

Parameters:
string|array $connections
string|array|null $tables
Returns:
Mage_Core_Model_Mysql4_Abstract

Definition at line 139 of file Abstract.php.

00140     {
00141         $this->_resources = Mage::getSingleton('core/resource');
00142 
00143         if (is_array($connections)) {
00144             foreach ($connections as $k=>$v) {
00145                 $this->_connections[$k] = $this->_resources->getConnection($v);
00146             }
00147         }
00148         elseif (is_string($connections)) {
00149             $this->_resourcePrefix = $connections;
00150         }
00151 
00152         if (is_null($tables) && is_string($connections)) {
00153             $this->_resourceModel = $this->_resourcePrefix;
00154         }
00155         elseif (is_array($tables)) {
00156             foreach ($tables as $k=>$v) {
00157                 $this->_tables[$k] = $this->_resources->getTableName($v);
00158             }
00159         }
00160         elseif (is_string($tables)) {
00161             $this->_resourceModel = $tables;
00162         }
00163         return $this;
00164     }

addUniqueField ( field  ) 

Add unique field restriction

Parameters:
array|string $field
Returns:
Mage_Core_Model_Mysql4_Abstract

Definition at line 401 of file Abstract.php.

00402     {
00403         $this->_initUniqueFields();
00404         if(is_array($this->_uniqueFields) ) {
00405             $this->_uniqueFields[] = $field;
00406         }
00407         return $this;
00408     }

afterLoad ( Mage_Core_Model_Abstract object  ) 

Definition at line 547 of file Abstract.php.

00548     {
00549         $this->_afterLoad($object);
00550     }

delete ( Mage_Core_Model_Abstract object  ) 

Delete the object

Parameters:
Varien_Object $object
Returns:
Mage_Core_Model_Mysql4_Abstract

Reimplemented in Mage_Admin_Model_Mysql4_User, and Mage_Api_Model_Mysql4_User.

Definition at line 384 of file Abstract.php.

00385     {
00386         $this->_beforeDelete($object);
00387         $this->_getWriteAdapter()->delete(
00388             $this->getMainTable(),
00389             $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId())
00390         );
00391         $this->_afterDelete($object);
00392         return $this;
00393     }

getChecksum ( table  ) 

Retrieve table checksum

Parameters:
string $table
Returns:
int

Reimplemented in Mage_Core_Model_Mysql4_Config.

Definition at line 608 of file Abstract.php.

00609     {
00610         if (!$this->_getConnection('read')) {
00611             return false;
00612         }
00613 
00614         if (is_array($table)) {
00615             $table = implode(',', $table);
00616         }
00617 
00618         $data = $this->_getConnection('read')->fetchAll('checksum table '.$table);
00619         $checksum = 0;
00620         foreach ($data as $row) {
00621             $checksum+= $row[self::CHECKSUM_KEY_NAME];
00622         }
00623         return $checksum;
00624     }

getIdFieldName (  ) 

Get primary key field name

Returns:
string

Definition at line 200 of file Abstract.php.

00201     {
00202         if (empty($this->_idFieldName)) {
00203             Mage::throwException(Mage::helper('core')->__('Empty identifier field name'));
00204         }
00205         return $this->_idFieldName;
00206     }

getMainTable (  ) 

Get main table name

Returns:
string

Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat.

Definition at line 213 of file Abstract.php.

00214     {
00215         if (empty($this->_mainTable)) {
00216             Mage::throwException(Mage::helper('core')->__('Empty main table name'));
00217         }
00218         return $this->getTable($this->_mainTable);
00219     }

getReadConnection (  ) 

Temporary resolving collection compatibility

Returns:
Zend_Db_Adapter_Abstract

Definition at line 288 of file Abstract.php.

00289     {
00290         return $this->_getReadAdapter();
00291     }

getTable ( entityName  ) 

Get table name for the entity

Parameters:
string $entityName

Definition at line 226 of file Abstract.php.

00227     {
00228         if (isset($this->_tables[$entityName])) {
00229             return $this->_tables[$entityName];
00230         }
00231         if (strpos($entityName, '/')) {
00232             $this->_tables[$entityName] = $this->_resources->getTableName($entityName);
00233         } elseif (!empty($this->_resourceModel)) {
00234             $this->_tables[$entityName] = $this->_resources->getTableName(
00235                 $this->_resourceModel.'/'.$entityName);
00236         } else {
00237             $this->_tables[$entityName] = $entityName;
00238         }
00239         return $this->_tables[$entityName];
00240     }

getUniqueFields (  ) 

Get configuration of all unique fields

Returns:
array

Definition at line 437 of file Abstract.php.

00438     {
00439         if (is_null($this->_uniqueFields)) {
00440             $this->_initUniqueFields();
00441         }
00442         return $this->_uniqueFields;
00443     }

load ( Mage_Core_Model_Abstract object,
value,
field = null 
)

Load an object

Parameters:
Mage_Core_Model_Abstract $object
mixed $value
string $field field to load by (defaults to model id)
Returns:
Mage_Core_Model_Mysql4_Abstract

Reimplemented in Mage_Admin_Model_Mysql4_Role, Mage_Admin_Model_Mysql4_User, Mage_Api_Model_Mysql4_Role, Mage_Api_Model_Mysql4_User, Mage_CatalogSearch_Model_Mysql4_Query, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, and Mage_Core_Model_Mysql4_Translate_String.

Definition at line 301 of file Abstract.php.

00302     {
00303         if (is_null($field)) {
00304             $field = $this->getIdFieldName();
00305         }
00306 
00307         $read = $this->_getReadAdapter();
00308         if ($read && !is_null($value)) {
00309             $select = $this->_getLoadSelect($field, $value, $object);
00310             $data = $read->fetchRow($select);
00311 
00312             if ($data) {
00313                 $object->setData($data);
00314             }
00315         }
00316 
00317         $this->_afterLoad($object);
00318 
00319         return $this;
00320     }

resetUniqueField (  ) 

Reset unique fields restrictions

Returns:
Mage_Core_Model_Mysql4_Abstract

Definition at line 415 of file Abstract.php.

00416     {
00417          $this->_uniqueFields = array();
00418          return $this;
00419     }

save ( Mage_Core_Model_Abstract object  ) 

Save object object data

Parameters:
Mage_Core_Model_Abstract $object
Returns:
Mage_Core_Model_Mysql4_Abstract

Not auto increment primary key support

Definition at line 343 of file Abstract.php.

00344     {
00345         if ($object->isDeleted()) {
00346             return $this->delete($object);
00347         }
00348 
00349         $this->_beforeSave($object);
00350         $this->_checkUnique($object);
00351 
00352         if (!is_null($object->getId())) {
00353             $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId());
00354             /**
00355              * Not auto increment primary key support
00356              */
00357             if ($this->_isPkAutoIncrement) {
00358                 $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition);
00359             } else {
00360                 $select = $this->_getWriteAdapter()->select($this->getMainTable(), array($this->getIdFieldName()))
00361                     ->where($condition);
00362                 if ($this->_getWriteAdapter()->fetchOne($select) !== false) {
00363                     $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition);
00364                 } else {
00365                     $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object));
00366                 }
00367             }
00368         } else {
00369             $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object));
00370             $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable()));
00371         }
00372 
00373         $this->_afterSave($object);
00374 
00375         return $this;
00376     }


Member Data Documentation

$_connections = array() [protected]

Definition at line 59 of file Abstract.php.

$_idFieldName [protected]

Definition at line 87 of file Abstract.php.

$_isPkAutoIncrement = true [protected]

Definition at line 94 of file Abstract.php.

$_mainTable [protected]

Definition at line 80 of file Abstract.php.

$_mainTableFields [protected]

Definition at line 96 of file Abstract.php.

$_resourceModel [protected]

Definition at line 66 of file Abstract.php.

$_resourcePrefix [protected]

Definition at line 52 of file Abstract.php.

$_resources [protected]

Definition at line 45 of file Abstract.php.

$_tables = array() [protected]

Definition at line 73 of file Abstract.php.

$_uniqueFields = null [protected]

Definition at line 115 of file Abstract.php.

const CHECKSUM_KEY_NAME = 'Checksum'

Definition at line 38 of file Abstract.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:58 2009 for Magento by  doxygen 1.5.8