[Solar-talk] Solar_Sql_Model - when a related record doesn't exist

Rodrigo Moraes rodrigo.moraes at gmail.com
Mon May 7 21:00:56 PDT 2007


On 5/8/07, Rodrigo Moraes wrote:
> The question is: shouldn't Solar_Sql_Model set the property to false
> or null when the related record doesn't exist, thus avoiding the
> warning and allowing us to check if the data exists?

The key is in _fetchRelated(). It seems to me that it should only
return a record when the result from fetch() is not null. Then you can
check the existence of the related data in a record. Something along
these lines:

    $data = $select->fetch('one');

    if($data) {
        // create and load into an appropriate Record object.
        $model = Solar::factory($opts['foreign_model']);
        $result = $model->_newRecord($data);
    } else {
        $result = null;
    }

Wouldn't it be better to be able to verify it? This is one option.
Another one is to call fetchNew() and return a new related record in
case the record doesn't exist. Anyway, I think it should never call
_newRecord() when $data is null. Thoughts?

rodrigo


More information about the solar-talk mailing list