NAME

Foorum::ResultSet::User - User object

FUNCTION

get
$schema->resultset('User')->get( { user_id => ? } );
$c->model('DBIC::User')->get( { username => ? } );
$c->model('DBIC::User')->get( { email => ? } );

get() do not query database directly, it try to get from cache, if not exists, get_from_db() and set cache. return is a hashref: (we may call it $user_obj below)

{
  user_id  => 1,
  username => 'fayland',
  # etc. from user table columns
  details  => {
      birthday => '1984-02-06',
      gtalk    => 'fayland'
      # etc. from user_details table columns
  },
  roles    => {
      1 => { admin => 1 },
      site => { admin => 1 },
      # etc. from user_roles, $field => { $role => 1 }
  }
  profile_photo => {
      type  => 'upload',
      value => 10,
      # etc. from user_profile_photo table columns
      upload => {
          upload_id => 10,
          filename  => 'fayland.jpg',
          # etc. from upload table columns
      }
  }
}
get_multi
$schema->resultset('User')->get_multi( user_id => [1, 2, 3]  );
$c->model('DBIC::User')->get_multi( username => ['fayland', 'testman'] );

get_multi() is to ease a loop for many users. if cache backend is memcached, it would use $memcached->get_multi(); to get cached user, and use get_from_db() to missing users. return is a hashref:

# $user_obj is the user hash above
1 => $user_obj,
2 => $user_obj,
# or
fayland => $user_obj,
testman => $user_obj,

(TODO: we may use { user_id => { 'IN' => \@user_ids } } for missing users.)

get_from_db()
$schema->resultset('User')->get_from_db( { user_id => ? } );
$c->model('DBIC::User')->get_from_db( { username => ? } );
$c->model('DBIC::User')->get_from_db( { email => ? } );

query db directly. return $user_obj

update_user()
$c->model('DBIC::User')->update_user( $user_obj, { update_column => $value } );

the difference between $row->update of DBIx::Class is that it delete cache.

delete_cache_by_user()
$schema->resultset('User')->delete_cache_by_user( $user_obj);
delete_cache_by_user_cond
$schema->resultset('User')->delete_cache_by_user_cond( { user_id => ? } );
$c->model('DBIC::User')->delete_cache_by_user_cond( { username => ? } );
$c->model('DBIC::User')->delete_cache_by_user_cond( { email => ? } );
update_threads_and_replies
$schema->resultset('User')->update_threads_and_replies($user);

get the correct 'threads' and 'replies' and update for user

get_user_settings
$c->model('DBIC::User')->get_user_settings( $user_obj);

get records from user_settings table. return is hashref

{
  send_starred_notification => 'N',
}

AUTHOR

Fayland Lam <fayland at gmail.com>