What''s the syntax for something like: f=Foo.(id==1) Here''s what I''ve tried: thufir@arrakis ~/goodfellow-tool $ thufir@arrakis ~/goodfellow-tool $ script/console Loading development environment.>> Call.find :all=> [#<Call:0xb6fca790 @attributes={"name"=>"zero", "id"=>"1", "end"=>"2007-01-01 18:00:00", "start"=>"2007-01-01 17:00:00", "login"=>"0123"}>]>>?> c => Call.1 SyntaxError: compile error (irb):3: syntax error, unexpected tASSOC, expecting $end c => Call.1 ^ from (irb):3>>?> c = Call.1 SyntaxError: compile error (irb):5: no .<digit> floating literal anymore; put 0 before dot c = Call.1 ^ (irb):5: syntax error, unexpected tINTEGER from (irb):5>> quitthufir@arrakis ~/goodfellow-tool $ thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 7 Feb 2008, at 21:06, Thufir wrote:> > What''s the syntax for something like: > > f=Foo.(id==1) >Haven''t you already had to do this dozens of times in your rails app? It''s just f = Foo.find 1 Fred> Here''s what I''ve tried: > > thufir@arrakis ~/goodfellow-tool $ > thufir@arrakis ~/goodfellow-tool $ script/console > Loading development environment. >>> Call.find :all > => [#<Call:0xb6fca790 @attributes={"name"=>"zero", "id"=>"1", > "end"=>"2007-01-01 18:00:00", "start"=>"2007-01-01 17:00:00", > "login"=>"0123"}>] >>> > ?> c => Call.1 > SyntaxError: compile error > (irb):3: syntax error, unexpected tASSOC, expecting $end > c => Call.1 > ^ > from (irb):3 >>> > ?> c = Call.1 > SyntaxError: compile error > (irb):5: no .<digit> floating literal anymore; put 0 before dot > c = Call.1 > ^ > (irb):5: syntax error, unexpected tINTEGER > from (irb):5 >>> quit > thufir@arrakis ~/goodfellow-tool $ > > > > > > thanks, > > Thufir > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Thu, 07 Feb 2008 21:16:49 +0000, Frederick Cheung wrote:> Haven''t you already had to do this dozens of times in your rails app? > It''s just f = Foo.find 1I''m trying to use the console a bit more. Does that specify that the id field==1, or does that just do a general search through all fields? I''d like to specify the id field/attribute. thanks, Thufir --~--~---------~--~----~------------~-------~--~----~ 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 Feb 7, 2008, at 7:17 PM, Thufir wrote:> On Thu, 07 Feb 2008 21:16:49 +0000, Frederick Cheung wrote: > >> Haven''t you already had to do this dozens of times in your rails app? >> It''s just f = Foo.find 1 > > I''m trying to use the console a bit more. Does that specify that > the id > field==1, or does that just do a general search through all fields? > I''d > like to specify the id field/attribute. > > thanks, > > ThufirThe console it just an irb session that has been initialized with your rails application. Anything that you can do with a model, you can do in the console. Not so much with controllers though as they expect to have request object. (In fact, this is IMHO one of the strongest examples of why the "fat model/skinny controller" style is the way to go.) Are you asking about how to indicate that your primary key is not called ''id''? If so, look at the docs for ''set_primary_key''. If you want to match some other column, you have the dynamic finders: Foo.find_by_id(1) or explicitly using conditions: Foo.find(:first, :conditions => [''id = ?'', 1]) Foo.find(:first, :conditions => { :id => 1 }) In every case, the docs are your friend here. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Excellent, thanks all :) thufir@arrakis ~/goodfellow-tool $ thufir@arrakis ~/goodfellow-tool $ script/console Loading development environment.>> Call.find :all=> [#<Call:0xb7087750 @attributes={"id"=>"1", "comment"=>"start work", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>, #<Call: 0xb7087714 @attributes={"id"=>"2", "comment"=>"start call", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>, #<Call: 0xb70876ec @attributes={"id"=>"3", "comment"=>"start break", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>, #<Call: 0xb70876c4 @attributes={"id"=>"4", "comment"=>"start work", "login_id"=>"2", "created_at"=>"2008-02-08 15:12:13"}>]>> Call.find_by_login_id(1)=> #<Call:0xb7081e40 @attributes={"id"=>"1", "comment"=>"start work", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>>> Call.find(:all, :conditions => { :login_id => 1 })=> [#<Call:0xb707c328 @attributes={"id"=>"1", "comment"=>"start work", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>, #<Call: 0xb707c300 @attributes={"id"=>"2", "comment"=>"start call", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>, #<Call: 0xb707c2d8 @attributes={"id"=>"3", "comment"=>"start break", "login_id"=>"1", "created_at"=>"2008-02-08 15:12:13"}>]>> quitthufir@arrakis ~/goodfellow-tool $ -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---