Answers.Body: <p>BaseComponentModel, BaseElementModel and BaseEntryRevisionModel all ultimately end up extending BaseModel, which itself extends <a href="http://www.yiiframework.com/doc/api/1.1/CModel" rel="nofollow">Yii's CModel</a>.</p>
  
  <p>I like to think of them, roughly, as beefed up <a href="https://en.wikipedia.org/wiki/Data_transfer_object" rel="nofollow">Data Transfer Objects</a>.  Primarily useful for transferring data throughout the various layers of Craft (templates, controllers, services, etc.).</p>
  
  <p>Regarding which ones you extend, it depends entirely on what you are trying to do in your plugin and with your Models.</p>
  
  <p>BaseModel is the most "generic" one as far as Craft is concerned that gives you all of the Craft specific attributes of Models.</p>
  
  <p>BaseElementModel is useful if your plugin is dealing with <a href="http://pixelandtonic.com/blog/craft-element-types" rel="nofollow">Element Types</a>.</p>
  
  <p>BaseComponentModel is useful if your plugin is dealing with Component Types (tools, widgets, tasks, etc.).  You can check the <code>craft/app/enums/ComponentType.php</code> enum for a full list.</p>
  
  <p>And BaseEntryRevisionModel is pretty self explanatory.</p>
  
  <p>And there is nothing stopping you from extending things like Craft's own <a href="http://buildwithcraft.com/docs/templating/entrymodel" rel="nofollow">EntryModel</a> directly, if you need specific features that it has.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-24T19:54:34.663Z
Answers.LastActivityDate: 2014-07-24T19:54:34.663Z
Answers.UserDisplayName: Brad Bell
Body: <p>In the <a href="http://buildwithcraft.com/docs/plugins/models" rel="nofollow">Craft Models documentation</a> example the model extends the BaseModel class. However in the <a href="https://github.com/pixelandtonic/Events/blob/master/events" rel="nofollow">example Events plugin source code</a> the Events_EventModel extends the BaseElementModel.</p>
  
  <p>While poking around in PHPStorm I also noticed other "base model" classes such as:</p>
  
  <ul>
  <li>BaseComponentModel</li>
  <li>BaseElementModel</li>
  <li>BaseEntryRevisionModel</li>
  </ul>
  
  <p>I also wondered if it makes sense to extend non-base models such as the EntryModel (if you're modeling entry data for example).</p>
  
Tags: <plugin-development><models>
Title: When should I build upon existing models in my own plugins?
ThreadText: # When should I build upon existing models in my own plugins?
  
  (Asked by: username_0 on 2014-07-24)
  
  In the [Craft Models documentation](http://buildwithcraft.com/docs/plugins/models) example the model extends the BaseModel class. However in the [example Events plugin source code](https://github.com/pixelandtonic/Events/blob/master/events) the Events\_EventModel extends the BaseElementModel.
  
  While poking around in PHPStorm I also noticed other "base model" classes such as:
  
  * BaseComponentModel
  * BaseElementModel
  * BaseEntryRevisionModel
  
  I also wondered if it makes sense to extend non-base models such as the EntryModel (if you're modeling entry data for example).
  
  **Tags:** plugin-development, models
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-24. Score: 2
  
  BaseComponentModel, BaseElementModel and BaseEntryRevisionModel all ultimately end up extending BaseModel, which itself extends [Yii's CModel](http://www.yiiframework.com/doc/api/1.1/CModel).
  
  I like to think of them, roughly, as beefed up [Data Transfer Objects](https://en.wikipedia.org/wiki/Data_transfer_object). Primarily useful for transferring data throughout the various layers of Craft (templates, controllers, services, etc.).
  
  Regarding which ones you extend, it depends entirely on what you are trying to do in your plugin and with your Models.
  
  BaseModel is the most "generic" one as far as Craft is concerned that gives you all of the Craft specific attributes of Models.
  
  BaseElementModel is useful if your plugin is dealing with [Element Types](http://pixelandtonic.com/blog/craft-element-types).
  
  BaseComponentModel is useful if your plugin is dealing with Component Types (tools, widgets, tasks, etc.). You can check the `craft/app/enums/ComponentType.php` enum for a full list.
  
  And BaseEntryRevisionModel is pretty self explanatory.
  
  And there is nothing stopping you from extending things like Craft's own [EntryModel](http://buildwithcraft.com/docs/templating/entrymodel) directly, if you need specific features that it has.
  
  
  ---
  
  