0

I want tableless AR object. Pseudo code:

# tablefull AR object
class Item < ActiveRecord::Base
  has_one :color
end

# tableless AR object, but persistant
class Color
  include ActiveAttr::Model
  belongs_to :item
  attribute :color
  Colors = [:yellow, :red, :black]
end

# expect
Color.first => #<Color id:1, color: :yellow>
Item.create(color: Color.first, foo: 'bar')
Item.where(color_id: Color.first)

I look at below so, but these are tableless and not persistant. How to create ActiveRecord tableless Model in Rails 3 Ruby on Rails: Fully functional tableless model

Community
  • 1
  • 1
Matt - sanemat
  • 5,418
  • 8
  • 37
  • 41

1 Answers1

0

You are using some terms in a non-standard way. When the Rails community (and most technical communities I know of) speaks of "persistence" they mean "saving data somewhere durable". This means, at least, "saving data someplace other than your application's memory" and it usually means "saving data in a way that will survive an application crash (e.g. to disk)." In the case of ActiveRecord, persistence means something very particular -- storage to a SQL database.

So, your example succeeds in getting a "tableless" model. If you want persistence with ActiveRecord, go with a normal (table-backed) model. I realize this may not be the answer you are looking for, but it is what you need to hear.

David J.
  • 31,569
  • 22
  • 122
  • 174