I am developing a RoR application with Firebird with its SQL engine, but I cannot understand why ActiveRecord (AR) continues to query the default database!
Here are the DDL tables:
CREATE TABLE GLOBAL_SETTINGS
(
SKEY varchar(64) NOT NULL,
SVALUE varchar(256) NOT NULL,
OBS blob sub_type 1,
IS_SYSTEM "BOOLEAN" DEFAULT 1 NOT NULL,
CREATED_AT timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
UPDATED_AT timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
CONSTRAINT PK_GLOBAL_SETTINGS_SKEY PRIMARY KEY (SKEY)
);
Here is the migration that created this table: ( create_global_settings.rb)
class CreateGlobalSettings < ActiveRecord::Migration
def up
create_table :global_settings, :id => false do |t|
t.string :skey, :null => false, :limit => 64
t.string :svalue, :null => false, :limit => 256
t.text :obs
t.boolean :is_system, :null => false, :default => true
t.timestamps :null => false
end
execute("alter table GLOBAL_SETTINGS alter column CREATED_AT set default CURRENT_TIMESTAMP;")
execute("alter table GLOBAL_SETTINGS alter column UPDATED_AT set default CURRENT_TIMESTAMP;")
execute("alter table GLOBAL_SETTINGS add constraint PK_GLOBAL_SETTINGS_SKEY primary key (SKEY)")
end
def down
drop_table :global_settings
end
end
Here is my model: ( global_Settings.rb)
class GlobalSettings < ActiveRecord::Base
validates :skey, presence: true
validates :skey, uniqueness: { case_sensitive: false, message: 'Global setting key allready exists!'}
validates :svalue, presence: true
end
Definitions or tests or helpers not defined!
In the rails console, if I do this:
gs = GlobalSettings.new(skey: 'testKey', svalue: 'testValue')
D, [2014-11-21T13:11:18.547669
D, [2014-11-21T13:11:18.564272
D, [2014-11-21T13:11:18.580900
gs.save
D, [2014-11-21T13:11:24.403986
D, [2014-11-21T13:11:24.543674
true
As you can see, it looks like AR is trying to get the default values for my model / table, in which case this is not required, as it queries the database 3 times, and it only needs to do the insert and letting the SQL engine take care of the rest. How to prevent this situation?
AR ?
, GlobalSetting sKey: sValue:, ?