laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

fix: morphTo when relation name is in camel case

Open willtj opened this issue 3 years ago • 1 comments

Commit e19e10a in this PR updates existing tests to use a 'multi-word' relation for the morph relationship. This means that:

  • imageable is changed to has_image when passed as the $name parameter to morphOne() and morphMany() Note that snake case is required here - the parent Eloquent getMorphs() method constructs the expected column names by appending '_id' and '_type' to the name that's passed.
  • imageable is changed to hasImage when accessed as the relation name

That commit causes RelationsTest::testMorph() to fail, then commit c02e584 fixes the issue in line with how Eloquent's morphTo() method works, where $name variable defaults to the name of the calling function and is only snake-cased when passed to getMorphs() (reference)

willtj avatar Sep 24 '21 15:09 willtj

Codecov Report

Merging #2318 (e26c877) into master (6aa6ad1) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2318   +/-   ##
=========================================
  Coverage     88.12%   88.12%           
  Complexity      664      664           
=========================================
  Files            33       33           
  Lines          1566     1566           
=========================================
  Hits           1380     1380           
  Misses          186      186           
Impacted Files Coverage Δ
src/Eloquent/HybridRelations.php 93.58% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6aa6ad1...e26c877. Read the comment docs.

codecov-commenter avatar Sep 24 '21 15:09 codecov-commenter

This was merged in #2498.

Thanks!

divine avatar Aug 26 '23 10:08 divine