I''m a little confused. (Again. Sorry for all the spam. Hope I''m not annoying anyone with all my questions.) I''m using the find_by_* active record methods to run some queries. This works: @email = Email.find_by_email "mailto:" + @params["q"] This also works: @email = Email.find_first ["sha1 = ?", @params["q"]] This doesn''t: @email = Email.find_by_sha1 @params["q"] Tosses an exception saying that find_by_sha1 method can''t be found. Shouldn''t that method just automagically exist because there''s a field on the table named sha1? -- Bob Aman
On 18.2.2005, at 21:01, Bob Aman wrote:> > Tosses an exception saying that find_by_sha1 method can''t be found. > Shouldn''t that method just automagically exist because there''s a field > on the table named sha1?Yes, it should. Just a wild guess, but sha1 might be among reserved words in rails. //jarkko> > -- > Bob Aman > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Friday 18 February 2005 17:13, Jarkko Laine wrote:> Yes, it should. Just a wild guess, but sha1 might be among reserved > words in rails.Or the regexp that matches those method_missings does not match digits. Line 755, activerecord''s base.rb if method_name =~ /find_(all_by|by)_([_a-z]+)/ --- Nicholas Seckar aka. Ulysses
> Or the regexp that matches those method_missings does not match digits. > > Line 755, activerecord''s base.rb > > if method_name =~ /find_(all_by|by)_([_a-z]+)/I was starting to suspect something like that. Is there a legit reason for this? -- Bob Aman
Bob Aman schrieb:>>Or the regexp that matches those method_missings does not match digits. >> >>Line 755, activerecord''s base.rb >> >> if method_name =~ /find_(all_by|by)_([_a-z]+)/ > > > I was starting to suspect something like that. Is there a legit > reason for this?Probably only that method names very seldomly end in a digit. This should be filed as a ticket. Sascha
On Sat, 19 Feb 2005 06:01:32 +0100, Sascha Ebach <se-eFwX6J65rk9VioaHkBSlcw02NpfuEekPhC4ANOJQIlc@public.gmane.org> wrote:> Bob Aman schrieb: > >>Or the regexp that matches those method_missings does not match digits. > >> > >>Line 755, activerecord''s base.rb > >> > >> if method_name =~ /find_(all_by|by)_([_a-z]+)/ > > > > > > I was starting to suspect something like that. Is there a legit > > reason for this? > > Probably only that method names very seldomly end in a digit. This > should be filed as a ticket.Um, ok. How? -- Bob Aman
Bob Aman:> Um, ok. How?http://dev.rubyonrails.com/newticket Sascha
Sascha Ebach wrote:> Bob Aman: > >> Um, ok. How? > > > http://dev.rubyonrails.com/newticket > > SaschaDon''t worry, I did it for you. Thanks for spotting this. http://dev.rubyonrails.com/ticket/670 Rgds
Hi! On Sat, 19 Feb 2005, Demetrius Nunes wrote the following:> Don''t worry, I did it for you. Thanks for spotting this. > http://dev.rubyonrails.com/ticket/670 >Wouldn''t it be better this way: ---------- if method_name =~ /find_(all_by|by)_([_a-z0-9]*)/ ---------- It allows for names like: - find_by_12abc - find_by_ab_234 - find_by__priv89xy - find_by_884427 (so that the name could start with a number too or even be made up just of numbers) bye Wolfgang
Wolfgang Klinger wrote:> > Wouldn''t it be better this way: > ---------- > if method_name =~ /find_(all_by|by)_([_a-z0-9]*)/ > ---------- > > It allows for names like: > - find_by_12abc > - find_by_ab_234 > - find_by__priv89xy > - find_by_884427If the column starts with anything other than a lowercase letter, then it won''t be possible for Rails to turn it into a proper class accessor method, like in: my_data.2123 => error So we''d better stick to Ruby syntax rules here. rgds Dema
On Sat, 19 Feb 2005, Demetrius Nunes wrote:> Wolfgang Klinger wrote: >> >> Wouldn''t it be better this way: >> ---------- >> if method_name =~ /find_(all_by|by)_([_a-z0-9]*)/ >> ---------- >> >> It allows for names like: >> - find_by_12abc >> - find_by_ab_234 >> - find_by__priv89xy >> - find_by_884427 > > If the column starts with anything other than a lowercase letter, then it > won''t be possible for Rails to turn it into a proper class accessor method, > like in: > > my_data.2123 => error > > So we''d better stick to Ruby syntax rules here.it''s true that''s not ruby syntax, but we know (and love) that ruby is more dynamic than that : harp:~ > cat a.rb class C def self.method_missing(m, *a, &b) p m end end C::send ''42'' harp:~ > ruby a.rb :42 a class could certainly #respond_to? a numeric method call. although this is probably bad mojo for ORM. it probably IS important to allow the method to start with one, or more, underscores and (possibly) to contain caps though harp:~ > cat a.rb class C class << self attr :__foobar__, true attr :__Barfoo__, true end end C::__foobar__ = 42 p C::__foobar__ C::__Barfoo__ = 42 p C::__Barfoo__ harp:~ > ruby a.rb 42 42 i think if method_name =~ /find_(all_by|by)_([_a-zA-Z][_a-zA-Z0-9]*)/ allows for all ''normal'' and proper ruby syntax (discounting ''!'' and ''?'' methods) but i''ve no idea about any additional ''rails'' rules. kind regards. -a -- ==============================================================================| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | When you do something, you should burn yourself completely, like a good | bonfire, leaving no trace of yourself. --Shunryu Suzuki ===============================================================================
Hi! On Sat, 19 Feb 2005, Demetrius Nunes wrote the following:> If the column starts with anything other than a lowercase letter, then > it won''t be possible for Rails to turn it into a proper class accessor > method, like in: >*oups* Didn''t think about that bye Wolfgang