9

My application doesn't need any database backend because it's kinda proxy server between client and another servers.

But I found that it would be nice to have all Active Record facilities (validation, associations and etc) in my project.

How to setup Active Record to not use database at all?

Ryan Bates in 219 cast "The Active Model" described only validation part but I need association facility.

megas
  • 21,401
  • 12
  • 79
  • 130
  • Well then what is the purpose of having an active record? They are meant to be used for the ease of access of databases right? – Praveen Puglia Dec 12 '12 at 12:00
  • 5
    @praveen: no, not necessarily. It's for the model in MVC which primarly is business logic and database is optional you could as well use them to access XML files, text files or web services. Question was asked many times before like [here](http://stackoverflow.com/questions/315850/rails-model-without-database) – thorsten müller Dec 12 '12 at 12:05
  • @thorstenmüller, I've read the link you posted but it's old one and maybe exits fresh solution. – megas Dec 12 '12 at 13:05
  • @megas, yes I agree. And not all answers are really good. That's why I didn't flag this question as duplicate or something like that. It's interesting and could do with a few new ideas. There may be even more old questions about it. I mostly pointed to it since it may help if nothing new comes up here. – thorsten müller Dec 12 '12 at 13:25
  • @thorstenmüller, thanks, as my understanding grows up it seems to me that it's not big problem to write association methods by myself. Am I correct? – megas Dec 12 '12 at 14:09
  • 1
    I haven't done this yet, but for associations it should be not much more than a simple method that retrieves the necessary data and then puts it into a hash structure that is nicely structured for your needs. I did something similar (outside ActiveRecord in a simple library) to get some data from Apache Solr. – thorsten müller Dec 12 '12 at 14:17

2 Answers2

4

Take a look at ActiveModel. That's what AR uses under the hood.

Jiří Pospíšil
  • 14,296
  • 2
  • 41
  • 52
4

These two gems could be what you want:

activemodel-associations

activemodel

Boti
  • 3,275
  • 1
  • 29
  • 54