Hi,
I have a model named 'Users', and a corresponding database table named 'users'. I've built some basic creation, getting, and setting functionality that has worked well thusfar.
I've run into a problem after changing the data type of my 'id' column in my database. I want to use GUIDs instead of numbers for identifying my users, but after changing the column data type from int to varchar, I get the following error:
PHP Fatal error: Uncaught exception 'Phalcon\\Mvc\\Model\\Exception' with message 'Column '1dffc8f8' doesn't belong to any of the selected models (1), when preparing: SELECT [Users].* FROM [Users] WHERE ([customerid] = :APR0:) AND id = 1dffc8f8-ec15-91c9-0d3e-9b1aafa1ffad' in /home/.../public_html/controllers/UsersController.php:255\nStack trace:\n#0 [internal function]: Phalcon\\Mvc\\Model\\Query->_getQualified(Array)\n#1 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(Array, true)\n#2 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(Array, true)\n#3 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(Array, true)\n#4 [internal function]:
Phalcon\\Mvc\\Model\\Query->_getExpression(Array, true)\n#5 [internal function]: Phalcon\\Mvc\\Model\\Query->_get
Expression(Array, true)\n#6 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(Array)\n#7 [internal function]: Phalcon\\Mvc\\Model\\Query->_prepareSelect()\n#8 [internal
function]: Phalcon\\Mvc\\Model\\Query->parse()\n#9 [internal function] in /home/.../public_html/controllers/UsersController.php on line 255
The line throwing the error is:
$user = $customer->getUsers("id = $userid")->getFirst();
But any other code that retreives users by id fails as well.
The part of the error where it says: "Column '1dffc8f8' doesn't belong to any of the selected models" Makes me think that Phalcon has somehow cached my table structure, and is now trying to find a column that no longer exists. However, I'm not aware of any caching that I've enabled, or where this might be getting cached. This error persists after a restart of Apache, and a restart of the MySQL server.
As soon as I change the data type back van varchar to int, the error disappears.
It would be great if anyone has any insight in what is going wrong, and how to fix this. Thanks very much in advance.
I'm running this on Phalcon 2.0.8 and MySQL.
Below is my model.
<?php
use Phalcon\Mvc\Model,
Phalcon\Mvc\Model\Validator\InclusionIn,
Phalcon\Mvc\Model\Validator\Uniqueness;
/**
* @property string username
* @property string email
* @property string password
* @property int status
* @property string firstName
* @property string lastName
* @property int telephoneNumber
* @property DateTime dateOfBirth
* @property int gender
* @property bool isAdmin
*/
class Users extends Model
{
public $customerid;
public function initialize()
{
$this->belongsTo("customerid", "Customers", "id");
$this->hasMany("id", "Statistics", "userid");
$this->hasOne("id", "Sessions", "userid");
$this->hasMany("id", "Images", "userid");
}
public function validation()
{
//active must be: 0 or 1
$this->validate(new InclusionIn(
array(
"field" => "status",
"domain" => array("0", "1")
)
));
//Email address must be unique
$this->validate(new Uniqueness(
array(
"field" => "email",
"message" => "The user's email must be unique"
)
));
//Check if any messages have been produced
if ($this->validationHasFailed() == true) {
return false;
}
}
}