File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 1212 * @property int $id
1313 * @property string $text
1414 * @property string $html
15- * @property int|null $parent_id
15+ * @property int|null $parent_id - Relates to local_id, not id
1616 * @property int $local_id
1717 * @property string $entity_type
1818 * @property int $entity_id
19+ * @property int $created_by
20+ * @property int $updated_by
1921 */
2022class Comment extends Model implements Loggable
2123{
@@ -38,7 +40,9 @@ public function entity(): MorphTo
3840 */
3941 public function parent (): BelongsTo
4042 {
41- return $ this ->belongsTo (Comment::class);
43+ return $ this ->belongsTo (Comment::class, 'parent_id ' , 'local_id ' , 'parent ' )
44+ ->where ('entity_type ' , '= ' , $ this ->entity_type )
45+ ->where ('entity_id ' , '= ' , $ this ->entity_id );
4246 }
4347
4448 /**
Original file line number Diff line number Diff line change @@ -210,16 +210,22 @@ public function test_notify_comment_replies()
210210 $ prefs = new UserNotificationPreferences ($ editor );
211211 $ prefs ->updateFromSettingsArray (['comment-replies ' => 'true ' ]);
212212
213+ // Create some existing comments to pad IDs to help potentially error
214+ // on mis-identification of parent via ids used.
215+ Comment::factory ()->count (5 )
216+ ->for ($ entities ['page ' ], 'entity ' )
217+ ->create (['created_by ' => $ this ->users ->admin ()->id ]);
218+
213219 $ notifications = Notification::fake ();
214220
215221 $ this ->actingAs ($ editor )->post ("/comment/ {$ entities ['page ' ]->id }" , [
216222 'text ' => 'My new comment '
217223 ]);
218- $ comment = $ entities ['page ' ]->comments ()->first ();
224+ $ comment = $ entities ['page ' ]->comments ()->orderBy ( ' id ' , ' desc ' )-> first ();
219225
220226 $ this ->asAdmin ()->post ("/comment/ {$ entities ['page ' ]->id }" , [
221227 'text ' => 'My new comment response ' ,
222- 'parent_id ' => $ comment ->id ,
228+ 'parent_id ' => $ comment ->local_id ,
223229 ]);
224230 $ notifications ->assertSentTo ($ editor , CommentCreationNotification::class);
225231 }
You can’t perform that action at this time.
0 commit comments