The guy who is designing our database seems to have specified some keys that are strings as well as some composite keys which are part integer and part string. I guess I could support that in rails by using find_by_sql() with no problem if I had to ? I will mention to him that it may be extra work etc.
Marnen Laibow-Koser
2009-Jun-22 16:50 UTC
Re: Rails with composite primary keys and string keys
Jedrin wrote:> The guy who is designing our database seems to have specified some > keys that are strings as well as some composite keys which are part > integer and part string. > > I guess I could support that in rails by using find_by_sql() with no > problem if I had to ?You could do even better. There''s a Rails plugin (don''t remember the name, but a Web search should find it) that makes Rails work transparently with composite keys. In any case, find_by_sql will probably not be necessary, since you can do find_by_key_field_1_and_key_field_2 or use :conditions.> > I will mention to him that it may be extra work etc.Tell him that Rails works better with a surrogate key... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Michael Schuerig
2009-Jun-22 19:03 UTC
Re: Rails with composite primary keys and string keys
On Monday 22 June 2009, Marnen Laibow-Koser wrote:> Jedrin wrote: > > The guy who is designing our database seems to have specified some > > keys that are strings as well as some composite keys which are part > > integer and part string. > > > > I guess I could support that in rails by using find_by_sql() with > > no problem if I had to ? > > You could do even better. There''s a Rails plugin (don''t remember the > name, but a Web search should find it) that makes Rails work > transparently with composite keys.http://compositekeys.rubyforge.org/ I''ve referred people to it in the past, but I''ve never used it myself. I''d love to hear that CPK works without a hitch with all the Rails versions and plugins you care to throw at it, however, I fear that this is not the case. The changes CPK needs to make all over Rails are rather intrusive and have to be adapted to the evolving code base. I''d expect a lot of code out there, plugins specifically, to tacitly assume that ids are plain numbers or can converted to numbers. Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/
Marnen Laibow-Koser
2009-Jun-22 19:55 UTC
Re: Rails with composite primary keys and string keys
Michael Schuerig wrote:> On Monday 22 June 2009, Marnen Laibow-Koser wrote: >> transparently with composite keys. > http://compositekeys.rubyforge.org/ > > I''ve referred people to it in the past, but I''ve never used it myself. > I''d love to hear that CPK works without a hitch with all the Rails > versions and plugins you care to throw at it, however, I fear that this > is not the case.It was the case for me, but it''s been quite a while since I actually used it. I was very impressed by how effortless and transparent the whole thing was. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.