[limb-issues] Created: (AR-10) Support for missing relation entities(nulify relations)

Pavel Shevaev (JIRA) jira at limb-project.com
Sat May 5 12:32:56 MSD 2007


Support for missing relation entities(nulify relations)
-------------------------------------------------------

                 Key: AR-10
                 URL: http://jira.limb-project.com/browse/AR-10
             Project: ACTIVE_RECORD
          Issue Type: New Feature
            Reporter: Pavel Shevaev


Sometimes relation entities can be missing in case they were deleted and it's ok. For example, say we have the following object:

class News extends lmbActiveRecord
{
  protected $_has_one = array('video' => array('field' => 'video_id',
                                               'class' => 'Video',
                                               'can_be_null' => true));
  ...
}

Say we have some news with video object. Now when video object is deleted it should set null for each news object, which is, firstly, can be time consuming and, secondly, video object may have now idea about any news objects(there's no relation definition in Video class). 

Currently there can be quite a dirty workaround by customizing loadOneToOneObject method:

  protected function _loadOneToOneObject($property)
  {
    try
    {
      return parent :: _loadOneToOneObject($property);
    }
    catch(lmbARException $e)
    {
      if($property == 'video')
        return null;
      else
        throw $e;
    }
  }

How about adding new property into relations, say, called 'nullify_missing' which would encapsulate the shown above logic for each relation? Thus class declaration will be as follows:

class News extends lmbActiveRecord
{
  protected $_has_one = array('video' => array('field' => 'video_id',
                                               'class' => 'Video',
                                               'nullify_missing' => true,
                                               'can_be_null' => true));
  ...
}

P.S. Actually this situation is usually handled on the database level using triggers which set nulls once the relation entity is deleted. However not every database supports triggers and foreign keys. 


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.limb-project.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the limb-issues mailing list