|
[Rails] legacy database, primary key compound with two fields: msg#03267RubyonRailsTalk
I am trying to define a model for a legacy database and the primary key is the combination of two fields, 'branchcode' and 'debtorno' class Custbranch < ActiveRecord::Base set_table_name 'custbranch' set_primary_key 'branchcode_branchno' end and I have tried... set_primary_key 'branchcode branchno' set_primary_key 'branchcode, branchno' but in the console, a simple find, always an error... >> @branch=Custbranch.find("A365") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'custbranch.branchcode_branchno' in 'where clause': SELECT * FROM `custbranch` WHERE (`custbranch`.`branchcode_branchno` = 'A365') >> @branch = Custbranch.find("A365") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'custbranch.branchcode branchno' in 'where clause': SELECT * FROM `custbranch` WHERE (`custbranch`.`branchcode branchno` = 'A365') >> @branch = Custbranch.find("A365") ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'custbranch.branchcode, branchno' in 'where clause': SELECT * FROM `custbranch` WHERE (`custbranch`.`branchcode, branchno` = 'A365') and the only way I seem to make it work is to use 'branchcode' as the primary key which is not indexed. I can use this for now but I am wondering if it is possible to set_primary_key on a legacy db model to use a compound index/primary key. Craig -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. --~--~---------~--~----~------------~-------~--~----~ 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@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
|
|
||||||||||||||||||||||||||
|
|
|
| News | Mail Home | sitemap | FAQ | advertise |