Answers.Body: <p>I just had a bit more of a look into this, I got the same error as you but by changing</p>
  
  <pre><code>'id' =&gt; array(AttributeType::Number, 'required' =&gt; true, 'unique' =&gt; true),
  </code></pre>
  
  <p>to just</p>
  
  <pre><code>id =&gt; AttributeType::Number
  </code></pre>
  
  <p>It fixed the issue and I was able to validate on it no problem, I don't think you need to worry about the ID being unique or being set on the model as this will be handled automatically by your record when you use it to save to the database, so you can be certain that every models id will always be unique.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-13T15:49:09.593Z
Answers.Text: cheers Alec this does work @bradbell would you agree on this solution?
Answers.UserDisplayName: Lettie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-13T14:41:53.233Z
Answers.LastActivityDate: 2015-05-13T14:41:53.233Z
Answers.UserDisplayName: Alec Ritson
Body: <p>Hi I'm getting this error when I try to validate a model.</p>
  
  <p>Craft\mymodelModel and its behaviors do not have a method or closure named "getTableSchema".</p>
  
  <p>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?</p>
  
  <pre><code>$model-&gt;setAttributes($attribute);
  
  if($model-&gt;validate()) {
      // code that sends model off to be saved
  } else {
      $model-&gt;getErrors();    
  }
  </code></pre>
  
  <p>Cheers</p>
  
  <p>Model class code:</p>
  
  <pre><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-&gt;name;
     }
  
     /**
       * Define the attributes this model will have.
       *
       * @return array
       */
       public function defineAttributes()
       {
          return array(
              'id'    =&gt; array(AttributeType::Number, 'required' =&gt; true, 'unique' =&gt; true),
          'field1'    =&gt; array(AttributeType::Number, 'required' =&gt; true),
          'field2' =&gt; array(AttributeType::Enum, 'values' =&gt; "value1,value2"),
          'field3'  =&gt; array(AttributeType::Enum, 'values' =&gt; "value1,value2,value3", 'required' =&gt; true, 'default' =&gt; 'value1'),
          'field4' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field5' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field6' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field7' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field8' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field9' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field10' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field11' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field12' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false),
          'field13' =&gt;  array(AttributeType::Name, 'maxLength' =&gt; 255, 'required' =&gt; false)
          );
      }
  
      /**
       * Get User
       */
      public function getmyModel()
      {
          if ($this-&gt;userId)
          {
              return craft()-&gt;users-&gt;getUserById($this-&gt;userId);
          }
      }
  
  }
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T10:15:22.207Z
Comments.Text: @carlcs the documentation refers to it under the models section though? http://buildwithcraft.com/docs/plugins/models
Comments.UserDisplayName: Lettie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T10:21:48.033Z
Comments.Text: Yep you're right, ignore my comment.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T11:40:22.983Z
Comments.Text: Are you able to post the code in your model class?
Comments.UserDisplayName: Alec Ritson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T13:55:47.387Z
Comments.Text: @AlecRitson no proplem. I've changed the name and field names for security.
Comments.UserDisplayName: Lettie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T14:17:12.413Z
Comments.Text: Okay, just to clarify, in your actual code. Your model class name follows `PluginHandle_ModelNameModel` convention and you are calling a new instance of the model like `new PluginHandle_ModelNameModel()` ? Just because in my experience with looking at errors with models, the exception should start `Craft\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. :)
Comments.UserDisplayName: Alec Ritson
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T14:39:53.707Z
Comments.Text: @AlecRitson yes sorry I should have changed it to the naming convention and yes to calling a new model
Comments.UserDisplayName: Lettie
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-13T14:41:11.373Z
Comments.Text: Can you enable devMode and share the full stack trace of the error?
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><models><validation>
Title: Error with model validation
ThreadText: # Error with model validation
  
  (Asked by: username_0 on 2015-05-13)
  
  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);
          }
      }
  
  }
  
  ```
  
  **Tags:** plugin-development, models, validation
  
  > **Comments:**
  > **username_0**: @username_1 the documentation refers to it under the models section though? http://buildwithcraft.com/docs/plugins/models  
  > **username_1**: Yep you're right, ignore my comment.  
  > **username_2**: Are you able to post the code in your model class?  
  > **username_0**: @username_2 no proplem. I've changed the name and field names for security.  
  > **username_2**: Okay, just to clarify, in your actual code. Your model class name follows `PluginHandle_ModelNameModel` convention and you are calling a new instance of the model like `new PluginHandle_ModelNameModel()` ? Just because in my experience with looking at errors with models, the exception should start `Craft\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. :)  
  > **username_0**: @username_2 yes sorry I should have changed it to the naming convention and yes to calling a new model  
  > **username_3**: Can you enable devMode and share the full stack trace of the error?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-05-13. Score: 1
  
  I just had a bit more of a look into this, I got the same error as you but by changing
  
  ```
  'id' => array(AttributeType::Number, 'required' => true, 'unique' => true),
  
  ```
  
  to just
  
  ```
  id => AttributeType::Number
  
  ```
  
  It fixed the issue and I was able to validate on it no problem, I don't think you need to worry about the ID being unique or being set on the model as this will be handled automatically by your record when you use it to save to the database, so you can be certain that every models id will always be unique.
  
  > **Comments:**
  > **username_0**: cheers username_2 this does work @username_3 would you agree on this solution?  
  
  ---
  
  