lucid icon indicating copy to clipboard operation
lucid copied to clipboard

feat: add test for null nested BelongsTo relationship

Open theRealPadster opened this issue 1 year ago • 5 comments

🔗 Linked issue

#1008

❓ Type of change

  • [x] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [ ] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This adds a test for nested belongsTo relationships, and checks for nulls. Right now BaseModel.toObject() throws an error when the model has a null preloaded relationship.

TypeError: Cannot read properties of null (reading 'toObject')
    at /app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1507:93
    at Array.reduce (<anonymous>)
    at Proxy.toObject (/app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1505:56)
    at /app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1507:93
    at Array.reduce (<anonymous>)
    at Proxy.toObject (/app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1505:56)
    at /app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1507:93
    at Array.reduce (<anonymous>)
    at Proxy.toObject (/app/node_modules/@adonisjs/lucid/build/src/Orm/BaseModel/index.js:1505:56)
    at new AdObject (/app/app/Libraries/Algolia/classes/AdObject.ts:16:25)

Should I add the fix in this PR as well? It will resolve #1008

📝 Checklist

  • [x] I have linked an issue or discussion.
  • [ ] I have updated the documentation accordingly.

theRealPadster avatar Feb 29 '24 15:02 theRealPadster

I think this should be good to go. The test does fail. Would the best practice be to include the fix in this PR or a separate one?

theRealPadster avatar Mar 23 '24 18:03 theRealPadster

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 01:04 stale[bot]

Bump...

theRealPadster avatar Apr 26 '25 01:04 theRealPadster

Hey @theRealPadster! 👋🏻

Could you please push this fix to the latest version of Lucid instead of 18.x?

RomainLanz avatar Apr 28 '25 07:04 RomainLanz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 18 '25 23:07 stale[bot]