Open
Description
Many of us have encountered a couple of situations where excluding certain fields on a related Model dynamically is necessary.
For such purpose, I think that the following feature should be added to future updates of the ORM.
Use case:
We have an API and we want to expose comments like so /api/comments.
We also want to know who was the user that submitted that comment, but we do not want it's email or password.
Current workaround:
### Model_User:
$_to_array_exclude(array('email', 'password'));
### API Controller:
$comments = Model_Comment::query()->related('users')->get();
$result = array();
foreach ($comments as $i => $comment)
{
$result[$i] = $comment->to_array();
}
return $result;
Note: This workaround has a big disadvantage. We will always exclude those fields when using ->to_array();
Proposed feature:
## Model_User:
We set nothing on the User's Model.
## API Controller:
$comments = Model_Comment::query()->related('users'=>array('to_array_exclude' => array('updated_at')))->get();
$result = array();
foreach ($comments as $i => $comment)
{
$result[$i] = $comment->to_array();
}
return $result;
Metadata
Metadata
Assignees
Labels
No labels