Frederick C. wrote:
You could just write the sql to create the table
Fred
I’ve done something similar for legacy DB that cannot follow the Rails
convention explicitly in postgreSQL in the past:-
So, in the migrations file:-
def self.up
# -----------------------------------------------------
# This is example postgreSQL specific DDL, have a think
# what is right for you
# -----------------------------------------------------
execute <<-EOF
create table public.<my_pluralized_model_name> (
mykey varchar(255) not null unique,
firstvalue varchar(255) not null,
secondvalue varchar(2000),
primary key (mykey)
);
EOF
end
So, substitute <my_pluralized_model_name> with your model name
“pluralized”.
You should know the score on this one by now.
You also seem to need to add a line in the model file itself to allow
rails to
pick up the new string identifier “mykey” as the ID:-
So …
class MyModelName < ActiveRecord::Base
set_primary_key “mykey”
end
Then, if you used the standard script/generate scaffold MyModelName,
you’ll have
a controller. All methods of which will work (for you to test with),
apart from the new, which I’m trying to figure at them moment.
With a non-standard PK defined at the table level, I’m getting
“WARNING: Can’t mass-assign these protected attributes: mykey”
I reckon this is because by default rails doesn’t like assignment of
PKs, but instead likes to assign PK values itself using aut-incrementing
DB specific single instance mechs, which don’t scale.
If there are any serious Rails dudes out there who know how I can crack
that last bit, it would save going back to the customer and persuading
them to re-engineer a legacy DB (which they won’t do)
Anyways, HTH