
Originally Posted by
allspiritseve
Really? Lets say on one page you need to find a user by ID:
user::find(array('id'=>89)); And then on another page, you need to find a user by another ID. How many times did you write this?
find() is one generic method that handles ALL circumstances.
PHP Code:
public static function _find($pClassName,$pOptions) {
if(self::isConnected()===false) throw new Exception('A database Adaptor has not been set for the '.__CLASS__.' Class.');
$model = ActiveRecordModelConfig::getModelConfig($pClassName);
$mode = !empty($pOptions) && is_array($pOptions[0])===false?array_shift($pOptions):self::findAll;
$node = new ActiveRecordSelectNode($model,new ActiveRecordFindConfig(!empty($pOptions)?$pOptions[0]:array()));
$select = strcasecmp($mode,self::findCount)==0?new ActiveRecordCount($node,$pOptions):new ActiveRecordSelect($node,$pOptions);
if(strcmp($mode,self::findSelect)==0) return $select; // return without reseting count
//echo '<p>',$select->toSql(),'</p>';
//echo '<pre>',print_r($select->getBindData()),'</pre>';
//return;
$stmt = $select->query(self::$_db);
ActiveRecordSelectNode::resetCount();
$collectionAgent = new ActiveRecordCollectionAgent($select);
if(strcmp($mode,self::findCount)==0) { return $stmt->fetchColumn(); }
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$collectionAgent->process($row,$node);
}
$records = $collectionAgent->getRecords();
return strcmp($mode,self::findOne)==0?count($records)!=0?$records[0]:null:$records;
}

Originally Posted by
allspiritseve
Twice. Even in a simple case like this, I'd rather duplicate a method name (getById()) than an array key. If I ever need to rename that method, I'm going to get a bunch of errors telling me exactly what code where used a nonexistent method. Yeah, it's a simple example, but the more you do at runtime, the more duplication you have.
There isn't any duplication. One find, save and delete method that are generic enough to handle most if not all circumstances.

Originally Posted by
allspiritseve
I disagree. A datasource object should only need enough information to correctly identify what it needs. In the case above, the id is all it needs. Considering how common finding by an ID is, I don't need to tell it what field to match.
Correct but what happens when you need to filter and add many more conditions? Either you would need to write a separate find method or make the finder generic. I prefer the ladder.

Originally Posted by
allspiritseve
Internally. That doesn't help me out when trying to figure out what to pass to your system to get it to do what I want. If I can't use your methods, what good is the interface to me? I'm stuck working with nested arrays. An array inside an array is probably fine, but any more than that is a pretty big indicator you have some refactoring to do.
The interface supports a very straightforward interface while also providing a very complex one. There aren't many system out there that support calculated columns, aggregates and subqueries. All of which are things that I have managed to integrate on the generic level without any hard coding or repetition. All ActiveRecord instances/classes inherit these functions.
Bookmarks