mpociot / teamwork

User to Team associations with invitation system for the Laravel 5 Framework
MIT License
1.07k stars 170 forks source link

Modified currentTeam() method and added currentTeam attribute #62

Closed codedninja closed 6 years ago

codedninja commented 7 years ago

While having issues trying to use withPivot() on currentTeam it would just error out. Turns out hasOne doesn't have that method so decided to fix the issue so you can grab data from the pivot table.

codedninja commented 7 years ago

Reason why it failed originally is because $user->currentTeam now gives pivot data back.

codecov-io commented 7 years ago

Current coverage is 73.78% (diff: 100%)

Merging #62 into master will decrease coverage by 1.56%

@@             master        #62   diff @@
==========================================
  Files            14         14          
  Lines           349        351     +2   
  Methods          61         62     +1   
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits            263        259     -4   
- Misses           86         92     +6   
  Partials          0          0          

Powered by Codecov. Last update 39abad1...818f506

mpociot commented 7 years ago

Thank you for the PR.

Wouldn't this break applications, that are using the relation to filter additional query parameters? For example:

$user->currentTeam()->where('foo', 'bar')->first();

This will no longer work, with your modification.

codedninja commented 7 years ago

Just compared both old version and new version and seems to be find. Also don't think you need to do $user->currentTeam()->where('foo', 'bar')->first(); since you only returning one relation.

I saw the currentTeam implementation in another application and it worked perfectly. You can still do $user->currentTeam->name or $user->currentTeam()->wherePivot('foo_id', 1)->first()

sschlein commented 6 years ago

Closed due to inactivity.