# Model without database table?

**URL:** <https://discuss.rubyonrails.org/t/model-without-database-table/25400>\
**Category:** rubyonrails-talk\
**Created:** [February 25, 2008, 6:28am UTC](https://discuss.rubyonrails.org/t/model-without-database-table/25400 "2008-02-25T06:28:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [February 25, 2008, 6:28am UTC](https://discuss.rubyonrails.org/t/model-without-database-table/25400/1 "2008-02-25T06:28:15Z")

</div>

Is it possible to make a model that does not map to a database table? If so how?

---

<div class="post-metadata">

**Author:** ![fxn](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/fxn/32/12956_2.png) [@fxn](https://discuss.rubyonrails.org/u/fxn)\
**Post date:** [February 25, 2008, 9:28am UTC](https://discuss.rubyonrails.org/t/model-without-database-table/25400/2 "2008-02-25T09:28:16Z")

</div>

A "model" is a class that represents something in the problem domain, Rails does not assume it is persistent. Just define a class Foo in app/models/foo.rb without inheriting from AR::Base.

-- fxn

---

<div class="post-metadata">

**Author:** ![jinsoo](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@jinsoo](https://discuss.rubyonrails.org/u/jinsoo)\
**Post date:** [February 27, 2008, 2:29am UTC](https://discuss.rubyonrails.org/t/model-without-database-table/25400/3 "2008-02-27T02:29:27Z")

</div>

I'm studying rails I am coding depot application in Agile web development with rails book I have Cart model code like that :

class Cart

&nbsp;&nbsp;&nbsp;attr\_reader :items

&nbsp;&nbsp;&nbsp;def initialize &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@items = &nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;def add\_product(product) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current\_item = @items.find {|item| item.product == product} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if current\_item &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;current\_item.increment\_quantity &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@items \<\< CartItem.new(product) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;def total\_price &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@items.sum { |item| item.price } &nbsp;&nbsp;&nbsp;end end above code is same with that of the book but depot app have a error Cart class doesn't inherit from ActiveRecode::Base But, Error message is like that \>\> c = Cart.new ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table  
'depots\_development.carts' doesn't exist: SHOW FIELDS FROM `carts`

plz, help me~

2008. 02. 25, 오후 6:28, Xavier Noria 작성:

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [October 6, 2009, 2:43pm UTC](https://discuss.rubyonrails.org/t/model-without-database-table/25400/4 "2009-10-06T14:43:51Z")

</div>

Sorry for the late answer, maybe it will be usefull for someone else.

You can use the following plugin: [http://agilewebdevelopment.com/plugins/activerecord\_base\_without\_table](http://agilewebdevelopment.com/plugins/activerecord_base_without_table)
