# ActiveRecord: using a YAML file instead of a DB table

**URL:** <https://www.ruby-forum.com/t/activerecord-using-a-yaml-file-instead-of-a-db-table/140749>\
**Category:** Rails\
**Created:** [June 18, 2008, 7:22am UTC](https://www.ruby-forum.com/t/activerecord-using-a-yaml-file-instead-of-a-db-table/140749 "2008-06-18T07:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [June 18, 2008, 7:22am UTC](https://www.ruby-forum.com/t/activerecord-using-a-yaml-file-instead-of-a-db-table/140749/1 "2008-06-18T07:22:58Z")

</div>

So, this may sound kind of “whacky”, but I’m trying to figure out a way  
to populate an ActiveRecord object using YAML instead of a DB table.  
I’m not even sure if this is actually feasible, but it sounds like a  
good way to increase the performance of a project I’m working on.

For instance, I have a model called CmsModules that contains information  
about the sections in a CMS. Modules are only added during development,  
so the table will never be updated while in production. The way things  
are currently set up, an SQL statement is executed on every page load in  
order to grab that information. I figure this is unnecessary, and I’d  
like to keep the same functionality without making those extra calls to  
the database.

I figure that I could use a YAML file to store the module information,  
therefore eliminating the need to access the database. Easy enough to  
do using YAML::load, but the problem is that I need to keep a HABTM  
relationship to the User model intact for access control. That’s where  
I’m lost…

So, my question is this - is there any way to have legit ActiveRecord  
objects populated from a YAML file, completely bypassing the database?

---

<div class="post-metadata">

**Author:** ![pond](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7ab992/32.png) [@pond](https://www.ruby-forum.com/u/pond)\
**Post date:** [June 18, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/activerecord-using-a-yaml-file-instead-of-a-db-table/140749/2 "2008-06-18T13:28:34Z")

</div>

Andrew H. wrote:

> So, this may sound kind of “whacky”, but I’m trying to figure out a way  
> to populate an ActiveRecord object using YAML instead of a DB table.

You must invent SQL-Ypath - a query notation for YAML that’s compatible  
with SQL.

> I’m not even sure if this is actually feasible, but it sounds like a  
> good way to increase the performance of a project I’m working on.

Such a language could never possibly be as performant as a tuned SQL  
database.  
Hordes of people work on those, for you.

> For instance, I have a model called CmsModules that contains information  
> about the sections in a CMS. Modules are only added during development,  
> so the table will never be updated while in production. The way things  
> are currently set up, an SQL statement is executed on every page load in  
> order to grab that information. I figure this is unnecessary, and I’d  
> like to keep the same functionality without making those extra calls to  
> the database.

Have you profiled these page hits? Maybe the database already caches  
things for  
you; that’s it’s job.

Next, look up MemCache, to explicitly cache database hits.

–  
Phlip
