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

hidden/visible properties on relation #58

Closed
blitzjs opened this issue Oct 23, 2013 · 4 comments · Fixed by #61
Closed

hidden/visible properties on relation #58

blitzjs opened this issue Oct 23, 2013 · 4 comments · Fixed by #61

Comments

@blitzjs
Copy link

blitzjs commented Oct 23, 2013

Currently hidden/visible properties only apply to the current model, but when displaying a model with relations, it would be nice to be able to limit what the relation shows, i.e.

model = Address
{
"city": "Los Angeles",
...

 "user_id": 10,
 "user": {
  //only show name
 }

}

Just like the other request allowing filtering on relations, we could use a dot to specify a hidden/visible relation property, i.e.

    $this->onRest('model.hidden.properties', function()
            {
                return ['user.password'];
            });
@evan108108
Copy link
Owner

👍 this is one that we should add for sure.

evan108108 added a commit that referenced this issue Oct 25, 2013
Issue #58: hidden/visible properties on relation
@evan108108
Copy link
Owner

@blitzjs I have updated RESTFullYii and now you can do things like this:

        $this->onRest('model.hidden.properties', function() {
            return ['password', 'id', '*.title', 'posts.id', '*.website'];
        });

        $this->onRest('model.visible.properties', function() {
            return ['username', 'email', 'posts.id', '*.title', 'profile.website'];
        });

The '*" is a wildcard that will act on all relations. I hope this helps and thanks again for the suggestion!

@blitzjs
Copy link
Author

blitzjs commented Oct 25, 2013

Thanks for addressing this so quickly!

@Dhineshtyr
Copy link

@evan108108 is it possible to hide overrided model's attribute. for example,

$this->onRest('model.company.override.attributes', function($model) {
    return array_merge($model->attributes, ['profile' => $model->profile]);
});

$this->onRest('model.hidden.properties', function() {
    return ['company.profile.logo'];
});

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 a pull request may close this issue.

3 participants