Skip to content

Fw Framework v1.0.2

Choose a tag to compare

@velkymx velkymx released this 13 Feb 05:04
· 106 commits to main since this release
067dc3c

This is a maintenance release focused on resolving a significant encapsulation bug within the ORM relationship logic that affected many-to-many queries.

Bug Fixes

**Fixed: Protected Property Access in BelongsToMany**

We identified an issue where the BelongsToMany relationship class was unable to retrieve the primary key of related models because it was attempting to access a protected static property from outside the class hierarchy.

  • Impact: This bug previously caused errors when calling $model->relationship()->get() or during eager loading if the primary key was not explicitly provided.
  • Resolution: Introduced a public accessor Model::getKeyName() to safely expose the primary key name to relationship handlers and other internal components.

Internal Changes

  • Enhanced Encapsulation: Added public static function getKeyName() to the base Model class.
  • Relationship Cleanup: Standardized BelongsToMany.php to use the new accessor, ensuring it no longer relies on direct property access which can be restricted by PHP's visibility rules.
  • Eager Loading Stability: Fixed an edge case where eager loading would fail to pluck the correct parent keys due to the visibility issue mentioned above.

Migration & Workarounds

If you were previously using a manual workaround like the one below:

// Old Workaround
$categoryIds = $post->categories()->pluck('category_id');
$categories = Category::whereIn('id', $categoryIds)->get();

You can now simplify your code back to the standard, expressive syntax:

// New & Fixed
$categories = $post->categories()->get();