How to create/save unary (pk-only) models

I have a table that’s currently only a primary key. Basically:

create_table “entites”, :force => true do |t|
end

class Entity < ActiveRecord::Base
has_many :entity_members
end

create_table “entity_membership”, :force => true do |t|
t.column “person_id”, :integer, :null => false
t.column “role”, :string, :null => false
t.column “entity_id”, :integer, :null => false
end

class EntityMembershp < ActiveRecord::Base
belongs_to :entity_member
belongs_to :person
end

The entity id is needed to link the aggregation to various other
models, but there’s no other information that can or should be
associated with it.

However I can’t seem to get the Entity class to create/save as it
doesn’t seem to auto-assign the id. From the console I’ve tried:

a = Entity.new
=> #<Entity:0x250fac0 @new_record=true, @attributes={}>

a.save
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or
near “)” at character 22
: INSERT INTO entities () VALUES()
[long error backtrace snipped]

a = Entity.create
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or
near “)” at character 22
: INSERT INTO entities () VALUES()

Is there anyway I can make this work? Is there anything cleaner than
adding a dummy column?

Eric

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs