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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 ....... ....... On 12/6/05, Onur Turgay <onurturgay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Dec 6, 2005, at 1:38 AM, Onur Turgay wrote:> 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 > onurOnur- 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 Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org