awobaz/compoships
Compoships enables Laravel Eloquent relationships on composite keys—match two or more columns for hasOne/hasMany/belongsTo, including eager loading. Ideal for legacy or third‑party schemas where single-column foreign keys aren’t possible.
Strengths:
DB::enableQueryLog()).Weaknesses:
hasOne, hasMany, and belongsTo (no belongsToMany, polymorphic, or custom scopes). Excludes 20–30% of Eloquent use cases.orders(warehouse_id, order_id)).vendor_id + contract_id → local_user_id).tenant_id + user_id) in shared databases.User and Task in the example). Impact: ~5–10 lines of code per model pair.ComposhipsFactory trait for testing, adding 1–2 lines per factory.where clauses in relationships (e.g., hasMany()->where('status', 'active') may fail with composite keys).with() + remember()).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Breaking Changes | High | Pin to 2.5.5; test nullable column behavior in staging. |
| Laravel Version Drift | Medium | Monitor Laravel 14+ compatibility; avoid auto-updates. |
| Performance Regression | Medium | Benchmark with DB::enableQueryLog(); avoid over-indexing composite keys. |
| Testing Gaps | High | Write integration tests for composite relationships; validate eager loading. |
| Dependency Conflicts | Low | Composer dependency is lightweight (MIT license); no known conflicts with Laravel. |
| Schema Lock-In | Medium | Document as a temporary solution; plan schema migration (e.g., surrogate keys). |
| Community Support | High | Limited; rely on GitHub issues/PRs for critical bugs. |
WHERE IN clauses.)hasOne, hasMany, or belongsTo? If not, Compoships is not a fit.2.5.5) to avoid version risks?DB::enableQueryLog().)ComposhipsFactory trait for relationship testing.with() + remember() for performance.| Phase | Steps | Effort | Risk |
|---|---|---|---|
| Assessment | Audit all composite relationships; validate use cases (e.g., legacy DB, multi-tenant). | Low | Low |
| Proof of Concept | Implement Compoships in a non-production environment; test eager loading, nullable columns, and edge cases. | Medium | Medium |
| Trait Adoption | Update all related models to extend Awobaz\Compoships\Database\Eloquent\Model or use the Compoships trait. |
Low | Low |
| Factory Updates | Add ComposhipsFactory trait to model factories; test relationship creation. |
Low | Low |
| Query Optimization | Ensure composite keys are indexed; benchmark with DB::enableQueryLog(). |
Medium | Medium |
| Testing | Write integration tests for composite relationships; validate edge cases (e.g., nullable columns, WHERE IN). |
High | High |
| Documentation | Update codebase docs to reflect Compoships usage; note sunset plan if applicable. | Low | Low |
| Deployment | Roll out in staging first; monitor query performance and errors. | Medium | Medium |
| Monitoring | Set up alerts for query timeouts or N+1 issues related to composite relationships. | Low | Low |
2.5.5 and monitor Laravel 14+ updates.hasMany()->where() may fail).How can I help you explore Laravel packages today?