I did two sql queries in the same environment and at the same time:
First:
Message.find_by_sql(["select * from messages where id = ?", 1])
Returns:
gumentError: wrong number of arguments (0 for 1)
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:1750:in `y''
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:1750:in `compute_type''
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:1316:in `instantiate''
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:532:in `find_by_sql''
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:532:in `collect!''
from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record
ase.rb:532:in `find_by_sql''
from (irb):11
Second:
Message.find_by_sql(["select * from messages where id = ?", 2])
Returns:
=> []
In table messages, there is a message with id 1, but no message with
id 2
also, I did this query with another table users, all worked well
My environment:
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
Rails 2.0.2
database: oracle 10
table messages has more columns than table users ...
Can anyone help me? Thanks!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Ok, i know what happened i have a column named "Type" and this makes everything happen can anyone tells me more details about this ? On Feb 15, 5:56 pm, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote:> I did two sql queries in the same environment and at the same time: > First: > Message.find_by_sql(["select * from messages where id = ?", 1]) > Returns: > gumentError: wrong number of arguments (0 for 1) > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:1750:in `y'' > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:1750:in `compute_type'' > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:1316:in `instantiate'' > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:532:in `find_by_sql'' > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:532:in `collect!'' > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > active_record > ase.rb:532:in `find_by_sql'' > from (irb):11 > Second: > Message.find_by_sql(["select * from messages where id = ?", 2]) > Returns: > => [] > In table messages, there is a message with id 1, but no message with > id 2 > also, I did this query with another table users, all worked well > My environment: > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > Rails 2.0.2 > database: oracle 10 > table messages has more columns than table users ... > Can anyone help me? Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
"type" is a preserved keyword in ActiveRecord for implementing "Single table inheritance", so don''t use it as a table column name. See c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:302 : # == Single table inheritance # # Active Record allows inheritance by storing the name of the class in a column that by default is named "type" (can be changed # by overwriting <tt>Base.inheritance_column</tt>). This means that an inheritance looking like this: # # class Company < ActiveRecord::Base; end # class Firm < Company; end # class Client < Company; end # class PriorityClient < Client; end # # When you do Firm.create(:name => "37signals"), this record will be saved in the companies table with type = "Firm". You can then # fetch this row again using Company.find(:first, "name = ''37signals''") and it will return a Firm object. # # If you don''t have a type column defined in your table, single-table inheritance won''t be triggered. In that case, it''ll work just # like normal subclasses with no special magic for differentiating between them or reloading the right type with find. # # Note, all the attributes for all the cases are kept in the same table. Read more: # http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html # - Regards, Jesse 2008/2/18, hei <cy_27-KN7UnAbNpbg@public.gmane.org>:> > > Ok, i know what happened > i have a column named "Type" > and this makes everything happen > can anyone tells me more details about this ? > > On Feb 15, 5:56 pm, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > I did two sql queries in the same environment and at the same time: > > First: > > Message.find_by_sql(["select * from messages where id = ?", 1]) > > Returns: > > gumentError: wrong number of arguments (0 for 1) > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:1750:in `y'' > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:1750:in `compute_type'' > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:1316:in `instantiate'' > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:532:in `find_by_sql'' > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:532:in `collect!'' > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > active_record > > ase.rb:532:in `find_by_sql'' > > from (irb):11 > > Second: > > Message.find_by_sql(["select * from messages where id = ?", 2]) > > Returns: > > => [] > > In table messages, there is a message with id 1, but no message with > > id 2 > > also, I did this query with another table users, all worked well > > My environment: > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > > Rails 2.0.2 > > database: oracle 10 > > table messages has more columns than table users ... > > Can anyone help me? Thanks! > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! On Feb 18, 1:53 pm, "Jesse Hu" <yiz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> "type" is a preserved keyword in ActiveRecord for implementing "Single table > inheritance", so don''t use it as a table column name. > > See c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:302 > : > > # == Single table inheritance > # > # Active Record allows inheritance by storing the name of the class in a > column that by default is named "type" (can be changed > # by overwriting <tt>Base.inheritance_column</tt>). This means that an > inheritance looking like this: > # > # class Company < ActiveRecord::Base; end > # class Firm < Company; end > # class Client < Company; end > # class PriorityClient < Client; end > # > # When you do Firm.create(:name => "37signals"), this record will be saved > in the companies table with type = "Firm". You can then > # fetch this row again using Company.find(:first, "name = ''37signals''") > and it will return a Firm object. > # > # If you don''t have a type column defined in your table, single-table > inheritance won''t be triggered. In that case, it''ll work just > # like normal subclasses with no special magic for differentiating between > them or reloading the right type with find. > # > # Note, all the attributes for all the cases are kept in the same table. > Read more: > #http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html > # > > - > Regards, > Jesse > > 2008/2/18, hei <cy...-KN7UnAbNpbg@public.gmane.org>: > > > > > > > Ok, i know what happened > > i have a column named "Type" > > and this makes everything happen > > can anyone tells me more details about this ? > > > On Feb 15, 5:56 pm, hei <cy...-KN7UnAbNpbg@public.gmane.org> wrote: > > > I did two sql queries in the same environment and at the same time: > > > First: > > > Message.find_by_sql(["select * from messages where id = ?", 1]) > > > Returns: > > > gumentError: wrong number of arguments (0 for 1) > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:1750:in `y'' > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:1750:in `compute_type'' > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:1316:in `instantiate'' > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:532:in `find_by_sql'' > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:532:in `collect!'' > > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record > > > ase.rb:532:in `find_by_sql'' > > > from (irb):11 > > > Second: > > > Message.find_by_sql(["select * from messages where id = ?", 2]) > > > Returns: > > > => [] > > > In table messages, there is a message with id 1, but no message with > > > id 2 > > > also, I did this query with another table users, all worked well > > > My environment: > > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32] > > > Rails 2.0.2 > > > database: oracle 10 > > > table messages has more columns than table users ... > > > Can anyone help me? Thanks!- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi,
U may try this query
Message.find_by_sql("select * from messages where id =
''2''").
On Feb 18, 2008 11:23 AM, Jesse Hu
<yizhih-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> "type" is a preserved keyword in ActiveRecord for implementing
"Single
> table inheritance", so don''t use it as a table column name.
>
> See
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:302
> :
>
> # == Single table inheritance
> #
> # Active Record allows inheritance by storing the name of the class in a
> column that by default is named "type" (can be changed
> # by overwriting <tt>Base.inheritance_column</tt>). This
means that an
> inheritance looking like this:
> #
> # class Company < ActiveRecord::Base; end
> # class Firm < Company; end
> # class Client < Company; end
> # class PriorityClient < Client; end
> #
> # When you do Firm.create(:name => "37signals"), this record
will be
> saved in the companies table with type = "Firm". You can then
> # fetch this row again using Company.find(:first, "name =
''37signals''")
> and it will return a Firm object.
> #
> # If you don''t have a type column defined in your table,
single-table
> inheritance won''t be triggered. In that case, it''ll work
just
> # like normal subclasses with no special magic for differentiating
> between them or reloading the right type with find.
> #
> # Note, all the attributes for all the cases are kept in the same table.
> Read more:
> # http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
> #
>
>
> -
> Regards,
> Jesse
>
> 2008/2/18, hei <cy_27-KN7UnAbNpbg@public.gmane.org>:
> >
> >
> > Ok, i know what happened
> > i have a column named "Type"
> > and this makes everything happen
> > can anyone tells me more details about this ?
> >
> > On Feb 15, 5:56 pm, hei <cy...-KN7UnAbNpbg@public.gmane.org>
wrote:
> > > I did two sql queries in the same environment and at the same
time:
> > > First:
> > > Message.find_by_sql(["select * from messages where id =
?", 1])
> > > Returns:
> > > gumentError: wrong number of arguments (0 for 1)
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:1750:in `y''
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:1750:in `compute_type''
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:1316:in `instantiate''
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:532:in `find_by_sql''
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:532:in `collect!''
> > > from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > > active_record
> > > ase.rb:532:in `find_by_sql''
> > > from (irb):11
> > > Second:
> > > Message.find_by_sql(["select * from messages where id =
?", 2])
> > > Returns:
> > > => []
> > > In table messages, there is a message with id 1, but no message
with
> > > id 2
> > > also, I did this query with another table users, all worked well
> > > My environment:
> > > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
> > > Rails 2.0.2
> > > database: oracle 10
> > > table messages has more columns than table users ...
> > > Can anyone help me? Thanks!
> > > >
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---