Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
$_to_array_exclude didn't exclude fields in query building
firewalker06
January 2013
Hi,
I'm trying to exclude some fields in my User model:
class Model_User extends \Orm\Model
{
protected static $_properties = array(
'id',
'username',
'password',
'email',
'activated',
'level',
'banned',
'ban_reason',
'new_password_key',
'new_password_requested',
'new_email',
'new_email_key',
'last_ip',
'last_login',
'created',
'modified',
'referral',
);
protected static $_to_array_exclude = array(
'password',
'activated',
'level',
'banned',
'ban_reason',
'new_password_key',
'new_password_requested',
'new_email',
'new_email_key',
'last_ip',
'referral'
);
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => true,
'property' => 'created',
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'mysql_timestamp' => true,
'property' => 'modified',
),
);
}
But it seems doesn't work, this is what I called:
$users = Model_User::find(2);
$this->response($users, 200);
All the fields still showing up. What could be wrong?
Harro
January 2013
A to_array filter does exactly that, it filters on to_array(). It will still query all fields to make sure the object cache is complete.
So use:
$this->response($users->to_array(), 200);
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
January 2013