When I try save, ActiveRecord keeps refering to a missing ID field. I really just want to use PK’s that don’t use autoincrement. Better yet that don’t use autoincrement and don’t have to be integer. I want to assign the value for the PK myself when I create a new record.
I have tried this:
Model:
class Job < ActiveRecord::Base
def before_create self.id = job_id
end
def self.reset_sequences(connection, table_names)
end
end
Here is the table:
CREATE TABLE [dbo].[jobs] (
job_id NOT NULL ,
job_desc (50) NULL ,
min_lvl NULL ,
max_lvl NULL) ON [PRIMARY]
It did not work and I have read “rumors” that this can somehow be accomplish by using
before_vaildate_on_create
but unfortunately no examples.
I think this is needed to connect to legacy schemas and get a more widespread usage of RoR.
Edit:
Have you ensured that jobid is valid?_
See this link, it does a pretty good job of covering this issue:
HowToUseNonDatabaseProvidedIDs
When I try save, ActiveRecord keeps refering to a missing ID field. I really just want to use PK’s that don’t use autoincrement. Better yet that don’t use autoincrement and don’t have to be integer. I want to assign the value for the PK myself when I create a new record.
I have tried this:
Model:
class Job < ActiveRecord::Base
def before_create self.id = job_id
end
def self.reset_sequences(connection, table_names)
end
end
Here is the table:
CREATE TABLE [dbo].[jobs] (
job_id NOT NULL ,
job_desc (50) NULL ,
min_lvl NULL ,
max_lvl NULL) ON [PRIMARY]
It did not work and I have read “rumors” that this can somehow be accomplish by using
before_vaildate_on_create
but unfortunately no examples.
I think this is needed to connect to legacy schemas and get a more widespread usage of RoR.
Edit:
Have you ensured that jobid is valid?_
See this link, it does a pretty good job of covering this issue:
HowToUseNonDatabaseProvidedIDs