Hi I'm getting this error when I try to validate a model.
Craft\mymodelModel and its behaviors do not have a method or closure named "getTableSchema".
I'm using the following code in the controller function that calls the save. It saves the data fine but I want to validate the model first before it does so but this is throwing the above error. What am I missing?
$model->setAttributes($attribute);
if($model->validate()) {
// code that sends model off to be saved
} else {
$model->getErrors();
}
Cheers
Model class code:
namespace Craft;
/**
* myModel Model
*
* Provides a read-only object representing a myModel, which is returned
* by our service class and can be used in our templates and controllers.
*/
class myModels_myModelModel extends BaseModel
{
/**
* Defines what is returned when someone puts {{ myModel }} directly
* in their template.
*
* @return string
*/
public function __toString()
{
return $this->name;
}
/**
* Define the attributes this model will have.
*
* @return array
*/
public function defineAttributes()
{
return array(
'id' => array(AttributeType::Number, 'required' => true, 'unique' => true),
'field1' => array(AttributeType::Number, 'required' => true),
'field2' => array(AttributeType::Enum, 'values' => "value1,value2"),
'field3' => array(AttributeType::Enum, 'values' => "value1,value2,value3", 'required' => true, 'default' => 'value1'),
'field4' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field5' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field6' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field7' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field8' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field9' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field10' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field11' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field12' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false),
'field13' => array(AttributeType::Name, 'maxLength' => 255, 'required' => false)
);
}
/**
* Get User
*/
public function getmyModel()
{
if ($this->userId)
{
return craft()->users->getUserById($this->userId);
}
}
}
PluginHandle_ModelNameModel
convention and you are calling a new instance of the model likenew PluginHandle_ModelNameModel()
? Just because in my experience with looking at errors with models, the exception should startCraft\PluginHandle_ModelNameModel
whereas the error you pasted doesn't , I understand you have changed the names of things, but I just wanted to make sure. :)