Feature Request #4290
Automatically creating tokens only when a token isn't set
| Status: | New | Start date: | 09/30/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | Modules:ORM | |||
| Target version: | - | |||
| Resolution: | Points: | 1 |
Description
It would be great if token generation was optional. I recently began working on a Facebook application and wanted to store each user's access token in the same table and access them later through the user token model. The create() method currently overwrites the token column regardless of whether it has already been set. I ended up coding around it by changing:
public function create(Validation $validation = NULL)
{
$this->token = $this->create_token();
return parent::create($validation);
}
To:
public function create(Validation $validation = NULL)
{
if ($this->token === NULL OR ORM::factory('user_token', array('token' => $token))->loaded())
{
$this->token = $this->create_token();
}
return parent::create($validation);
}
This way, a token is only generated when the one set is NULL or already exists. I found it to be a useful functionality that would allow for more flexibility. Any thoughts?
History
Updated by Gabriel Evans over 1 year ago
Pull request: https://github.com/kohana/orm/pull/41