Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Proper Functionality For Tables Without Auto-Increment PK #17

Merged
merged 1 commit into from Jan 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/arjdbc/teradata/adapter.rb
Expand Up @@ -137,7 +137,7 @@ def _execute(sql, name = nil)
end if self.class.lowercase_schema_reflection end if self.class.lowercase_schema_reflection
result result
elsif self.class.insert?(sql) elsif self.class.insert?(sql)
(@connection.execute_insert(sql) or last_insert_id(sql)).to_i (@connection.execute_insert(sql) or last_insert_id(_table_name_from_insert(sql))).to_i
else else
@connection.execute_update(sql) @connection.execute_update(sql)
end end
Expand Down
18 changes: 18 additions & 0 deletions spec/models/no_autoincrement_pk.rb
@@ -0,0 +1,18 @@
class CreateNoAutoincrementPks < ActiveRecord::Migration
def self.up
create_table :no_autoincrement_pks, :id=>false do |t|
t.integer :post_id
t.string :title
t.timestamps
end
end

def self.down
drop_table :no_autoincrement_pks
end

end

class NoAutoincrementPk < ActiveRecord::Base
self.primary_key = 'post_id'
end
17 changes: 17 additions & 0 deletions spec/no_autoincrement_pk_spec.rb
@@ -0,0 +1,17 @@
require 'spec_helper'
require 'models/no_autoincrement_pk'

describe 'NoAutoincrementPkSpec' do
it 'should be able to create a record and manually set the post_id' do
CreateNoAutoincrementPks.up
obj = NoAutoincrementPk.new
obj.post_id = 12345
obj.title = 'Sample title with 3 or more periods ...'
obj.save.should be_true
obj.reload
obj.id.should eq(12345)
found = NoAutoincrementPk.find(12345)
found.id.should eq(12345)
CreateNoAutoincrementPks.down
end
end