Forum: Ruby on Rails yaml problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
onurturgay (Guest)
on 2005-12-06 11:39
(Received via mailing list)
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
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
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

        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


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
509-577-7732
removed_email_address@domain.invalid
This topic is locked and can not be replied to.