Fixed \XF\Mvc\Entity\Manager :: getRelationFinder doesn't support "key"

DragonByte Tech

Well-known member
Affected version
2.0.10
Given the following relation:
PHP:
            'Subscriptions' => [
                'entity' => 'DBTech\Mail:Subscription',
                'type' => self::TO_MANY,
                'conditions' => 'mailing_list_id',
                'key' => 'user_id',
                'cascadeDelete' => true
            ],
Running this code:
PHP:
$mailingList->getRelationFinder('Subscriptions')
I would expect the resulting Finder to have keyedBy set.

Proposed patch to \XF\Mvc\Entity\Manager:
Diff:
--- src/XF/Mvc/Entity/Manager.php    2018-09-11 19:49:57.000000000
+++ src/XF/Mvc/Entity/Manager.php    2018-10-03 12:29:38.000000000
@@ -443,12 +443,17 @@
             foreach ((array)$relation['with'] AS $extraWith)
             {
                 $finder->with($extraWith);
             }
         }

+        if (!empty($relation['key']))
+        {
+            $finder->keyedBy($relation['key']);
+        }
+      
         if (!empty($relation['order']))
         {
             $finder->setDefaultOrder($relation['order']);
         }

         if (!empty($relation['proxy']))
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.0 Beta 6).

Change log:
When calling getRelationFinder (potentially via getRelation) on an entity, if the relation is keyed, use that as the array key instead of the normal primary key.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top Bottom