Forum: Ruby on Rails yaml problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
onurturgay (Guest)
on 2005-12-06 11:39
(Received via mailing list)
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)
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
the YAML into my application (in console) and sidebar.blocks is there..
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
but whenever I try to access it queries the database.

Thanks in advance
onurturgay (Guest)
on 2005-12-06 11:44
(Received via mailing list)
can it be a bug of to_yaml? here is an excerpt from yaml file. blocks is
a part of attributes. is it correct?

--- !ruby/object:Sidebar
  name: main_sidebar
  default: "1"
  id: "1"
  - !ruby/object:Block
      name: static
      current_config: >2-
        --- !ruby/hash:HashWithIndifferentAccess

        title: network siteleri
ezra (Guest)
on 2005-12-06 18:53
(Received via mailing list)
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


	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.

-Ezra Z.
Yakima Herald-Republic
This topic is locked and can not be replied to.