Frederick Cheung wrote:
> On Apr 8, 5:35�am, Greg Willits <rails-mailing-l...@andreas-s.net>
> wrote:
> 
>> When I use the code above, I get data from Article (good), Extras
>> (good), and Assets (bad), and nothing from Pages (curious).
>>
>> I don't understand why Assets is being included, and I don't know how to
>> keep that data out of the results.
>>
> 
> Odd. Maybe you could show the sql it is executing ?

Hmm. now I am seeing something different.

With this code (more verbatim this time).......

class Article < ActiveRecord::Base

  self.primary_key = 'rcrd_id'

  has_many  :extras,
            :dependent => :destroy

  has_many  :pages,
            :order => 'sortOrder',
            :dependent => :destroy

  has_many  :assets,
            :dependent => :destroy

  def self.get_list
    list = self.find(:all,
      :include => [:extras],
      :conditions => [
        "#{self.table_name}.rcrd_status='Y' AND ready='Y' AND 
publishDate <= :today",
        {:today => Date.today.to_s} ])
  end
end

Or with this code......

def self.get_list
  list = self.find(:all,
    :conditions => [
      "#{self.table_name}.rcrd_status='Y' AND ready='Y' AND publishDate 
<= :today",
      {:today => Date.today.to_s} ])
end

I now see these same queries in the log.....
(and this is restarting Rails after each time I change the code, just to 
be sure)

   [4;36;1mArticle Load (1.6ms) [0m    [0;1mSELECT * FROM `articles` 
WHERE (articles.rcrd_status='Y' AND ready='Y' AND publishDate <= 
'2009-04-08')  [0m
   [4;35;1mAsset Load (0.8ms) [0m    [0mSELECT * FROM `assets` WHERE 
(`assets`.article_id = 'abc123')  [0m
   [4;36;1mExtra Load (1.1ms) [0m    [0;1mSELECT * FROM `extras` WHERE 
(`extras`.article_id = 'abc123')  [0m

I know it was different before, I even showed someone to confirm it.

I don't see anything odd about the other models, they both have a simple 
belongs_to articles statement, and nothing else. Pages has a belongs_to 
articles, and a has_many to another model. Maybe that keeps pages from 
being loaded?

So, I dunno. But shouldn't that second finder case (without :include) 
not be returning :assets nor :extras? I end up using debug() to output 
the results to confirm what is actually being loaded, and I get those 
two associations, but no :pages data. Seems weird.

-- gw


-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to