Hi I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart from I just ran into an issue. Lets say I have a model called MyModel that has 150 records. If in IRB I try:> test = MyModel.allOnly 138 records are returned. If I now try:> lastRecord = test.lastThe record I get has an ID of 138 And yet if I try:> test.countIt returns the correct value - 50! Any ideas on what is going on? -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3f80a79c80a823ff4b39e73741f0e3b0%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On 5 July 2013 18:06, zip py <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > > I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart > from I just ran into an issue. > > Lets say I have a model called MyModel that has 150 records. > > If in IRB I try: > >> test = MyModel.all > > Only 138 records are returned.How do you know?> > If I now try: > >> lastRecord = test.last > > The record I get has an ID of 138If you have not specified an order clause then the order you get the records in is undefined, so the last record is not necessarily the highest id.> > And yet if I try: > >> test.count > > It returns the correct value - 50!I presume you mean 150 Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLugY7o6g3wRTHcOz-AAJykkyeQ530XU8n2s9vG0%3DvrMBw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Hi, As of Rails 4, the order is by default based on the id DESC. So Model.last produces the following sql: *SELECT * FROM models ORDER BY models.id DESC LIMIT 1* That said, I''ve no idea why you only get a part of the records back. Were you able to validates all those numbers directly on the DB? Regards Geoffroy Op vrijdag 5 juli 2013 23:16:14 UTC+2 schreef Colin Law het volgende:> > On 5 July 2013 18:06, zip py <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org <javascript:>> wrote: > > Hi > > > > I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart > > from I just ran into an issue. > > > > Lets say I have a model called MyModel that has 150 records. > > > > If in IRB I try: > > > >> test = MyModel.all > > > > Only 138 records are returned. > > How do you know? > > > > > If I now try: > > > >> lastRecord = test.last > > > > The record I get has an ID of 138 > > If you have not specified an order clause then the order you get the > records in is undefined, so the last record is not necessarily the > highest id. > > > > > And yet if I try: > > > >> test.count > > > > It returns the correct value - 50! > > I presume you mean 150 > > Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/56352800-fcf0-4ad1-80b1-a1bcb75290f2%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On 6 July 2013 11:15, Geoffroy Gomet <geoffroy.gomet-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > As of Rails 4, the order is by default based on the id DESC. > So Model.last produces the following sql: > > SELECT * FROM models ORDER BY models.id DESC LIMIT 1 > > > That said, I''ve no idea why you only get a part of the records back.It is likely that he is getting all records back (as shown by #count) and that 138 is the lowest id. Colin> > Were you able to validates all those numbers directly on the DB? > > Regards > > Geoffroy > > Op vrijdag 5 juli 2013 23:16:14 UTC+2 schreef Colin Law het volgende: >> >> On 5 July 2013 18:06, zip py <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> > Hi >> > >> > I have a Rail 4 with Postrgesql 9.1 setup that is working fine, apart >> > from I just ran into an issue. >> > >> > Lets say I have a model called MyModel that has 150 records. >> > >> > If in IRB I try: >> > >> >> test = MyModel.all >> > >> > Only 138 records are returned. >> >> How do you know? >> >> > >> > If I now try: >> > >> >> lastRecord = test.last >> > >> > The record I get has an ID of 138 >> >> If you have not specified an order clause then the order you get the >> records in is undefined, so the last record is not necessarily the >> highest id. >> >> > >> > And yet if I try: >> > >> >> test.count >> > >> > It returns the correct value - 50! >> >> I presume you mean 150 >> >> Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLufE9m_MsiCtYnoeaKHebHjM_CjyksyZrssh6AFaE%2BGVA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law wrote in post #1114588:> It is likely that he is getting all records back (as shown by #count) > and that 138 is the lowest id.Nope:) The reason I noticed is that when I did a find all I wasn''t getting new records that had been added. However, if I get the new records by their id they definitely exist. It''s got odder this morning, there are now 155 records, and a find all returns the latest records, however records id 139 to 145 are missing! Again, I can get them by id. But using Webmin to list the records, I get exactly the same result - so it is looking like a database issue. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c2e5fd8bc9b47f38000e3562a8604621%40ruby-forum.com. For more options, visit https://groups.google.com/groups/opt_out.
On Monday, July 8, 2013 5:26:15 AM UTC-4, Ruby-Forum.com User wrote:> > Colin Law wrote in post #1114588: > > It is likely that he is getting all records back (as shown by #count) > > and that 138 is the lowest id. > > > Nope:) > > The reason I noticed is that when I did a find all I wasn''t getting new > records that had been added. > > However, if I get the new records by their id they definitely exist. > > It''s got odder this morning, there are now 155 records, and a find all > returns the latest records, however records id 139 to 145 are missing! > Again, I can get them by id. > > But using Webmin to list the records, I get exactly the same result - so > it is looking like a database issue. > > -- >I''ve been trying but am unable to duplicate your problem. I''m running on rails4 with postgresql9.1 and pg (0.15.1). Here''s my simple test: 1) rails new CheckItOut -d postgresql 2) cd CheckItOut 3) rails generate scaffold Number name:string value:integer 4) rake db:create 5) rake db:migrate 6) rails console> n = 0 > while (n < 200) { >> name = sprintf("%04d", n) >> Number.create(:name => name, :value => n) >> n += 1 }7) rails server 8) browsing to localhost:3000/numbers shows an index with 200 entries of the expected names and values Try these steps to see if you really have the database problem as you''ve reported it or if what you''re seeing is a result of something lurking in your app.> 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f1d7fbc8-aacf-4c3e-badd-74bcdbed9052%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On Jul 8, 2013, at 3:26 AM, zip py wrote:> The reason I noticed is that when I did a find all I wasn''t getting new > records that had been added. > > However, if I get the new records by their id they definitely exist. > > It''s got odder this morning, there are now 155 records, and a find all > returns the latest records, however records id 139 to 145 are missing! > Again, I can get them by id. > > But using Webmin to list the records, I get exactly the same result - so > it is looking like a database issue.1) Watch the rails app log to see what SQL is being issued. 2) It really sounds like somewhere you''re keeping a transaction open, which is why you see different versions of the db. -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5F4437E6-D294-48B3-87BE-CC6183A6E888%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.