<p>I might be wrong here, but I don't think a model can be used to save entries. You populate a model, then populate a record with that model and save it. Once saved, you get data from the db as a record, then populate a model with it to pass that to a view, for instance.</p>

<p>If everything works as it should, a record is never used outside the service.</p>

CC BY-SA 3.0
2015-05-01T14:15:49.967Z
The underlying CActiveRecord class contains hasErrors and getErrors methods.
Jay
CC BY-SA 3.0
2014-12-18T06:45:02.913Z
Nailed it. In rare instances, you might modify a record's properties just before saving (or just after retrieving). But if that data ever leaves your service layer, it should do so as a model.
Lindsey D
CC BY-SA 3.0
2014-12-18T14:56:59.337Z
How does this work when updating an existing record? https://gist.github.com/russback/f6d96809a459e3872363 shows how I'm currently doing it but it feels a little odd to have to declare a model just to access the allErrors property (it doesn't exist on the BaseRecord class.
Russ Back
CC BY-SA 3.0
2014-12-17T20:33:13.880Z
2014-12-17T20:33:13.880Z
Paul
<p>If a Model can be used to save entries, what is a Record for? Is it literally just to define the schema? I've seen a few examples where the defineAttributes methods have duplication of code too, so I'm a little confused...</p>

CC BY-SA 3.0
2014-12-18T02:53:58.710Z
There is a good explanation of models vs. records in Craft here: http://craftcms.stackexchange.com/a/2973/57
Brad Bell
CC BY-SA 3.0
2014-12-18T09:53:54.497Z
Thanks, Brad. I'd like to echo one of the comments on that article in that it would be great if this detail was in the docs.
Russ Back
<plugin-development><database><models><records>
Models v Records - confused
# Models v Records - confused

(Asked by: username_0 on 2014-12-17)

If a Model can be used to save entries, what is a Record for? Is it literally just to define the schema? I've seen a few examples where the defineAttributes methods have duplication of code too, so I'm a little confused...

**Tags:** plugin-development, database, models, records
> **Comments:**
> **username_1**: There is a good explanation of models vs. records in Craft here: http://craftcms.stackexchange.com/a/2973/57  
> **username_0**: Thanks, Brad. I'd like to echo one of the comments on that article in that it would be great if this detail was in the docs.  

---

## 1 answers

### Answer by username_2 on 2014-12-17. Score: 6 | Accepted answer

I might be wrong here, but I don't think a model can be used to save entries. You populate a model, then populate a record with that model and save it. Once saved, you get data from the db as a record, then populate a model with it to pass that to a view, for instance.

If everything works as it should, a record is never used outside the service.

> **Comments:**
> **username_4**: Nailed it. In rare instances, you might modify a record's properties just before saving (or just after retrieving). But if that data ever leaves your service layer, it should do so as a model.  
> **username_0**: How does this work when updating an existing record? https://gist.github.com/russback/f6d96809a459e3872363 shows how I'm currently doing it but it feels a little odd to have to declare a model just to access the allErrors property (it doesn't exist on the BaseRecord class.  
> **username_3**: The underlying CActiveRecord class contains hasErrors and getErrors methods.  

---

