# Yaml problem

**URL:** <https://www.ruby-forum.com/t/yaml-problem/95422>\
**Category:** Rails\
**Created:** [December 6, 2005, 10:39am UTC](https://www.ruby-forum.com/t/yaml-problem/95422 "2005-12-06T10:39:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![onurturgay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecc23a/32.png) [@onurturgay](https://www.ruby-forum.com/u/onurturgay)\
**Post date:** [December 6, 2005, 10:39am UTC](https://www.ruby-forum.com/t/yaml-problem/95422/1 "2005-12-06T10:39:51Z")

</div>

hi,  
I have a has\_many association between my sidebar and its blocks.

class Sidebar  
has\_many :blocks

class Block  
belongs\_to :sidebar

I select them by using i.e. @sidebar = Sidebar.find(1,:include=\>:blocks)  
and  
this gives me my sidebar and its blocks in one query.

Then I save this @sidebar variable into a YAML file for fast access and  
deployment. I checked the YAML file by eye and it seems ok. Then I  
reload  
the YAML into my application (in console) and sidebar.blocks is there…  
but  
whenever I try to access sidebar.blocks it queries the database. What  
can be  
wrong in this setup? The blocks is loaded from yaml file (console shows  
it)  
but whenever I try to access it queries the database.

Thanks in advance  
onur

---

<div class="post-metadata">

**Author:** ![onurturgay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecc23a/32.png) [@onurturgay](https://www.ruby-forum.com/u/onurturgay)\
**Post date:** [December 6, 2005, 10:44am UTC](https://www.ruby-forum.com/t/yaml-problem/95422/2 "2005-12-06T10:44:08Z")

</div>

can it be a bug of to\_yaml? here is an excerpt from yaml file. blocks is  
not  
a part of attributes. is it correct?

— !ruby/object:Sidebar  
attributes:  
name: main\_sidebar  
default: “1”  
id: “1”  
blocks:

- !ruby/object:Block  
attributes:  
name: static  
current\_config: \>2-  
— !ruby/hash:HashWithIndifferentAccess

…  
…

---

<div class="post-metadata">

**Author:** ![onurturgay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecc23a/32.png) [@onurturgay](https://www.ruby-forum.com/u/onurturgay)\
**Post date:** [December 6, 2005, 5:53pm UTC](https://www.ruby-forum.com/t/yaml-problem/95422/3 "2005-12-06T17:53:31Z")

</div>

On Dec 6, 2005, at 1:38 AM, Onur T. wrote:

> (1,:include=\>:blocks) and this gives me my sidebar and its blocks  
> Thanks in advance  
> onur

Onur-

```
What are you trying to do exactly? You want to save an AR object as

```

yaml so you can reload it later without hitting the database? Is that  
it? If so then I recommend reloading the yaml into a different  
variable that is not an actual AR object. It seems that you are  
trying to short circuit AR by loading yaml instead of hitting the db?  
I don’t think this will work correctly the way you are trying to do  
it. So just try loading the yaml into anonther var.

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid
