Ruby on Rails 3 (3.1) ActiveModel Associations (tableless nested models)

WHITECOLOR picture WHITECOLOR · Jul 6, 2011 · Viewed 8.3k times · Source

How to impliment ActiveModel associations (tableless nested models)?

For example:

book has many chapters

With ActiveRecord I would create two models and assosiate them with has_many and belongs_to. But ActiveModel doesn't have such functionality. How can I implement this?

Answer

Jarl picture Jarl · Aug 5, 2011

With rails versions >= 2.3.x you can use the activerecord-tableless gem. With that gem you can have associations and validations without a database.

Update

I have been added as author to the gem and I have updated the gem to support newer Rails versions. So now we can have tableless models with associations in Rails versions >= 2.3