I have the following relationships: Document :has_many Proposals :has_many ProposalVersions. This fails:>> Document.first.proposals.first.proposal_versions.size=> 0 But this works:>> Proposal.find(1).proposal_versions.size=> 2 Here''s the SQL from the first statement: SELECT count(*) AS count_all FROM "proposal_versions" WHERE ("proposal_versions".proposal_id = 2) The failing SQL in the first example seems really dangerous, because it apparently picks an ID at random (and this obviously works also with non-count queries, resulting in possibly returning the wrong set of data: Where does the ''2'' come from? Neither Document or Proposal has ID 2, they''re both ID 1. Is this expected behaviour? I''m on rails 2.2.1 (eh, 2.2 RC2). Linux. SQlite. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 17, 11:56 pm, sigvei <sigve.indreg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have the following relationships: > > Document :has_many Proposals :has_many ProposalVersions. > > This fails:>> Document.first.proposals.first.proposal_versions.sizeDo you mean Document.find(:first)... ?> > => 0 > > But this works:>> Proposal.find(1).proposal_versions.size > > => 2 > > Here''s the SQL from the first statement: > > SELECT count(*) AS count_all FROM "proposal_versions" WHERE > ("proposal_versions".proposal_id = 2) > > The failing SQL in the first example seems really dangerous, because > it apparently picks an ID at random (and this obviously works also > with non-count queries, resulting in possibly returning the wrong set > of data: > > Where does the ''2'' come from? Neither Document or Proposal has ID 2, > they''re both ID 1. > > Is this expected behaviour? > > I''m on rails 2.2.1 (eh, 2.2 RC2). Linux. SQlite.-- Daniel Bush --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Nov, 14:38, Daniel Bush <dlb.id...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 17, 11:56 pm, sigvei <sigve.indreg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have the following relationships: > > > Document :has_many Proposals :has_many ProposalVersions. > > > This fails:>> Document.first.proposals.first.proposal_versions.size > > Do you mean Document.find(:first)... ?ActiveRecord::Base::first is a convenience wrapper for ActiveRecord::Base::find(:first), according to the API. So I can''t quite see why that should make a difference. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 17 Nov 2008, at 14:19, sigvei wrote:> > On 17 Nov, 14:38, Daniel Bush <dlb.id...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On Nov 17, 11:56 pm, sigvei <sigve.indreg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> I have the following relationships: >> >>> Document :has_many Proposals :has_many ProposalVersions. >> >>> This fails:>> Document.first.proposals.first.proposal_versions.size >> >> Do you mean Document.find(:first)... ? > > ActiveRecord::Base::first is a convenience wrapper for > ActiveRecord::Base::find(:first), according to the API. So I can''t > quite see why that should make a difference.is there a document/proposal with id=2 (you''ve sort of implied that there isn''t, but I''m not quite sure) Fred> > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 18, 1:19 am, sigvei <sigve.indreg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 17 Nov, 14:38, Daniel Bush <dlb.id...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Nov 17, 11:56 pm, sigvei <sigve.indreg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have the following relationships: > > > > Document :has_many Proposals :has_many ProposalVersions. > > > > This fails:>> Document.first.proposals.first.proposal_versions.size > > > Do you mean Document.find(:first)... ? > > ActiveRecord::Base::first is a convenience wrapper for > ActiveRecord::Base::find(:first), according to the API. So I can''t > quite see why that should make a difference.Sorry. Wasn''t familiar with it. Hard to imagine rails putting in a random id. Can only surmise that Document.first.proposals.first.id==2 I don''t think any order is guaranteed either unless you''ve specified :order somewhere so it may change randomly depending on your database. Maybe you added a new proposal with no proposal versions in addition to proposal with id=1. Or a new document even. -- Daniel Bush --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---