Answers.Body: <blockquote>
    <p>Problem is: so far as I can tell, nobody's written the book.</p>
  </blockquote>
  
  <p>That's partly our fault... we've never really documented the Attribute parts of Models and Records.  And it probably won't happen now since the majority of that has been stripped out of the upcoming Craft 3 making it much easier to follow Yii 2 conventions (which happens to be way more documented).</p>
  
  <blockquote>
    <p>What is the Name type used for?</p>
  </blockquote>
  
  <p>In the context of a Record, it's a shortcut for saying you're going to get a <code>varchar</code> datatype set to 255 chars.  In the context of a Model, it'll just enforce the 255 character limit.</p>
  
  <blockquote>
    <p>What's the difference between Handle and Slug? Why choose one over the other?</p>
  </blockquote>
  
  <p>A handle is a <code>varchar(255)</code> that has a few pre-defined reserve words.  <code>id, dateCreated, dateUpdated, uid, title</code>.  Currently used in Craft for defining the <code>handles</code> that things like Asset Sources, Global Sets, Asset Transforms, etc. uses.</p>
  
  <p>There isn't a <code>AttributeType::Slug</code>.</p>
  
  <blockquote>
    <p>What exactly does <code>Template</code> do, and why does it need its own type?</p>
  </blockquote>
  
  <p>It's just a shortcut for a <code>varchar(500)</code>, currently used in Craft when defining a template path for Category and Section settings.</p>
  
  <blockquote>
    <p>What's the difference between Url and Uri? Is it just the validation?</p>
  </blockquote>
  
  <p>Semantically, a URL is a subset of a URI: <a href="https://danielmiessler.com/study/url-uri/" rel="nofollow">https://danielmiessler.com/study/url-uri/</a></p>
  
  <p>In the context of Craft, yeah - the only practical difference is the validation.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-06T00:35:41.183Z
Answers.Text: Good to hear that Yii 2/Craft 3 have this issue licked! Thanks for the response. I've ended up getting most of my questions answered by trolling through the source, but this was a bit of a pain. Honestly, I just ended up using Enums aside from Strings and Mixed types this time around, but it was puzzling. Thanks!
Answers.UserDisplayName: Gavin Anderegg
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-05T23:22:54.820Z
Answers.LastActivityDate: 2016-07-05T23:22:54.820Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm building a plugin which creates a few tables, and need to store some fairly robust data. I've done this before and previously gotten by with mostly <code>AttributeType::String</code> and <code>AttributeType::Mixed</code>, but this time I'd like to ensure I'm doing things by the book. Problem is: so far as I can tell, nobody's written the book.</p>
  
  <p>I started out by <a href="https://craftcms.com/docs/plugins/models" rel="nofollow">Model</a> and <a href="https://craftcms.com/docs/plugins/records" rel="nofollow">Record</a> documentation, but they don't reference the possible AttributeType options. Next I read the <a href="https://craftcms.com/classreference/enums/AttributeType" rel="nofollow">class reference</a>, but this isn't helpful either. Then I looked at the <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/ModelHelper.php" rel="nofollow">ModelHelper</a> and <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/DbHelper.php" rel="nofollow">DbHelper</a> code. These were a bit helpful, but they don't explain how exactly an AttributeType affects throughout Craft. Eventually I found Experience's <a href="https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes" rel="nofollow">Definitive Guide to Validation in Craft series</a> (specifically the linked AttributeType entry). This is quite helpful, but because it's focused mostly on validation, it doesn't answer many of my questions.</p>
  
  <p>It's possible that <a href="https://leanpub.com/craft-validation" rel="nofollow">the book by Experience</a> answers gives more detail, but I'm surprised I need a book to learn about this. It also seems like a slight gamble, as I'm only potentially interested in one chapter right now.</p>
  
  <p>Here's the sort of thing I'm hoping to learn:</p>
  
  <ul>
  <li>What is the <code>Name</code> type used for?</li>
  <li>What's the difference between <code>Handle</code> and <code>Slug</code>? Why choose one over the other?</li>
  <li>What exactly does <code>Template</code> do, and why does it need its own type?</li>
  <li>What's the difference between <code>Url</code> and <code>Uri</code>? Is it just the validation?</li>
  </ul>
  
  <p>Maybe it's not important to know these things, but I think it would be helpful to understand what I'm doing and how these types are processed and affect the system. It's also not completely clear what types are available, as the ModelHelper source doesn't list types like <code>String</code>. I assume that's getting inherited from Yii, but I'm not certain.</p>
  
  <p><strong>Question:</strong>
  Is there some documentation, or blog post, out there that explains the types available through <code>AttributeType</code>? </p>
  
Tags: <plugin-development><models><records><attribute>
Title: Model/Record AttributeType documentation?
ThreadText: # Model/Record AttributeType documentation?
  
  (Asked by: username_0 on 2016-07-04)
  
  I'm building a plugin which creates a few tables, and need to store some fairly robust data. I've done this before and previously gotten by with mostly `AttributeType::String` and `AttributeType::Mixed`, but this time I'd like to ensure I'm doing things by the book. Problem is: so far as I can tell, nobody's written the book.
  
  I started out by [Model](https://craftcms.com/docs/plugins/models) and [Record](https://craftcms.com/docs/plugins/records) documentation, but they don't reference the possible AttributeType options. Next I read the [class reference](https://craftcms.com/classreference/enums/AttributeType), but this isn't helpful either. Then I looked at the [ModelHelper](https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/ModelHelper.php) and [DbHelper](https://github.com/pixelandtonic/Craft-Release/blob/master/app/helpers/DbHelper.php) code. These were a bit helpful, but they don't explain how exactly an AttributeType affects throughout Craft. Eventually I found Experience's [Definitive Guide to Validation in Craft series](https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-2-attributetypes) (specifically the linked AttributeType entry). This is quite helpful, but because it's focused mostly on validation, it doesn't answer many of my questions.
  
  It's possible that [the book by Experience](https://leanpub.com/craft-validation) answers gives more detail, but I'm surprised I need a book to learn about this. It also seems like a slight gamble, as I'm only potentially interested in one chapter right now.
  
  Here's the sort of thing I'm hoping to learn:
  
  * What is the `Name` type used for?
  * What's the difference between `Handle` and `Slug`? Why choose one over the other?
  * What exactly does `Template` do, and why does it need its own type?
  * What's the difference between `Url` and `Uri`? Is it just the validation?
  
  Maybe it's not important to know these things, but I think it would be helpful to understand what I'm doing and how these types are processed and affect the system. It's also not completely clear what types are available, as the ModelHelper source doesn't list types like `String`. I assume that's getting inherited from Yii, but I'm not certain.
  
  **Question:**
  Is there some documentation, or blog post, out there that explains the types available through `AttributeType`?
  
  **Tags:** plugin-development, models, records, attribute
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-07-05. Score: 2 | Accepted answer
  
  > Problem is: so far as I can tell, nobody's written the book.
  
  That's partly our fault... we've never really documented the Attribute parts of Models and Records. And it probably won't happen now since the majority of that has been stripped out of the upcoming Craft 3 making it much easier to follow Yii 2 conventions (which happens to be way more documented).
  
  > What is the Name type used for?
  
  In the context of a Record, it's a shortcut for saying you're going to get a `varchar` datatype set to 255 chars. In the context of a Model, it'll just enforce the 255 character limit.
  
  > What's the difference between Handle and Slug? Why choose one over the other?
  
  A handle is a `varchar(255)` that has a few pre-defined reserve words. `id, dateCreated, dateUpdated, uid, title`. Currently used in Craft for defining the `handles` that things like Asset Sources, Global Sets, Asset Transforms, etc. uses.
  
  There isn't a `AttributeType::Slug`.
  
  > What exactly does `Template` do, and why does it need its own type?
  
  It's just a shortcut for a `varchar(500)`, currently used in Craft when defining a template path for Category and Section settings.
  
  > What's the difference between Url and Uri? Is it just the validation?
  
  Semantically, a URL is a subset of a URI: <https://danielmiessler.com/study/url-uri/>
  
  In the context of Craft, yeah - the only practical difference is the validation.
  
  > **Comments:**
  > **username_0**: Good to hear that Yii 2/Craft 3 have this issue licked! Thanks for the response. I've ended up getting most of my questions answered by trolling through the source, but this was a bit of a pain. Honestly, I just ended up using Enums aside from Strings and Mixed types this time around, but it was puzzling. Thanks!  
  
  ---
  
  