Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope relationship options #4851

Merged
merged 2 commits into from
Apr 2, 2020
Merged

Scope relationship options #4851

merged 2 commits into from
Apr 2, 2020

Conversation

emptynick
Copy link
Collaborator

@emptynick emptynick commented Apr 1, 2020

This allows to use a local scope on the related model in a relationship.

Usage:
Create a scope, for example

public function scopeActive($query)
{
    return $query->where('active', 1);
}

and add to the relationship options:

{
    "scope": "active"
}

Supersedes #4760

@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #4851 into 1.4 will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                1.4    #4851      +/-   ##
============================================
- Coverage     60.37%   60.34%   -0.04%     
- Complexity     1370     1373       +3     
============================================
  Files           194      194              
  Lines          3990     3992       +2     
============================================
  Hits           2409     2409              
- Misses         1581     1583       +2     
Impacted Files Coverage Δ Complexity Δ
src/Http/Controllers/VoyagerBaseController.php 58.22% <0.00%> (-0.30%) 139.00 <0.00> (+3.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 cfee641...8e049d1. Read the comment docs.

@emptynick emptynick merged commit 11e212a into thedevdojo:1.4 Apr 2, 2020
@emptynick emptynick deleted the relationship-scope branch April 2, 2020 10:22
@pcorrick
Copy link

pcorrick commented Apr 3, 2020

I'm getting the following error in laravel.log, when I click any dropdown BREAD field related to a relationship (Add or Edit). The field says "the results could not be loaded".

[2020-04-03 15:17:01] production.ERROR: Undefined property: stdClass::$scope {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined property: stdClass::$scope at [APPNAME]/vendor/tcg/voyager/src/Http/Controllers/VoyagerBaseController.php:860)

@emptynick
Copy link
Collaborator Author

Is $options an object in your case? Or just an empty string?

@pcorrick
Copy link

pcorrick commented Apr 3, 2020

I'm pretty new to php/laravel, I think $options is a json formatted string, which in my case doesn't have a scope property (yet).

I commented out lines 860-862 in VoyagerBaseControler.php and I can see the dropdown contents again.

Then I uncommented those lines and put in a scope property (empty string) into the relationship properties, and I can see the dropdown contents for that relationship (but not any others).

Relationship details is now:
{
"display": {
"width": "4"
},
"scope": ""
}

@MrCrayon
Copy link
Collaborator

MrCrayon commented Apr 3, 2020

!empty($options)

should cover all cases without throwing an error, 0 is not used anyway.

@emptynick
Copy link
Collaborator Author

I think property_exists($options, 'scope') should work better.

@MrCrayon
Copy link
Collaborator

MrCrayon commented Apr 3, 2020

If we are sure $options is always an object

@emptynick
Copy link
Collaborator Author

Yes, there's an accessor in the datarow model decoding it.

@mjomble
Copy link

mjomble commented Apr 3, 2020

I also encountered this error just now.

A fix that worked for me was editing line 860 in VoyagerBaseController and changing

if ($options->scope && ...

to

if (isset($options->scope) && ...

@emptynick
Copy link
Collaborator Author

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants