Reputation: 305
I have my AttachmentsMembers table with the migration as:
class AttachmentsMembers < ActiveRecord::Migration
def change
create_table :attachments_members, :id => false do |t|
t.references :attachment, :null => false
t.references :member, :null => false
end
add_index :attachments_members, [:attachment_id, :member_id]
end
end
If I try to delete any record from my console then I get the following error:
ActiveRecord::StatementInvalid: PG::Error: ERROR: zero-length delimited identifier at or near """"
LINE 1: ...OM "attachments_members" WHERE "attachments_members"."" = $1
^
: DELETE FROM "attachments_members" WHERE "attachments_members"."" = $1
from /home/icicle/.rvm/gems/ruby-2.0.0-p353@ltbuddy/gems/activerecord-3.2.18/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `prepare
Code for AttachmentsMember model:
class AttachmentsMember < ActiveRecord::Base
#Relationships
belongs_to :attachment
belongs_to :member
end
In attachment model:
belongs_to :user, class_name: 'User', foreign_key: 'user_id'
belongs_to :attachable, polymorphic: true
belongs_to :referable, polymorphic: true
has_many :attachments, as: :referable, :dependent => :destroy
has_many :attachments_members, :dependent => :destroy
has_many :members, :through => :attachments_members, :dependent => :destroy
In member model:
belongs_to :user, class_name: 'User', foreign_key: 'user_id'
belongs_to :case, class_name: 'Case', foreign_key: 'case_id'
belongs_to :user_type, class_name: 'UserType', foreign_key: 'user_type_id'
has_many :attachments_members, dependent: :destroy
has_many :attachments, :through => :attachments_members, dependent: :destroy
has_many :documents_members, dependent: :destroy
has_many :documents, :through => :documents_members, dependent: :destroy
Even if do AttachmentsMember.last from my console I get the same error but AttachmentsMember.first works.
Any someone explain why the issue is coming?
Upvotes: 1
Views: 149
Reputation: 305
Resolved the issue by creating the primary key for AttachmentsMember table
Upvotes: 1