#1478 confirmed
Xavier Shay

Record with enum in a CPK cannot be destroyed

Reported by Xavier Shay | January 17th, 2011 @ 10:43 PM | in 1.1.1

When using an enum as part of a CPK, you cannot destroy the record. Observe:

require 'rubygems'
require 'dm-core'
require 'dm-migrations'
require 'dm-types'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'postgres://localhost/test') # createdb test

class User
  include DataMapper::Resource

  property :id, Serial

  has n, :posts

class Post
  include DataMapper::Resource

  property :id, Serial,  :key => true
  property :type, Enum[:a, :b], :key => true
  property :title, String

  belongs_to :user


user = User.create(:posts => [{:type => :a, :title => "Post A"}, {:type => :b, :title => "Post B"}])

post = user.posts.first
puts post.destroy # => true
puts Post.all.map(&:title) # ...but record is not destroyed!

There is a dodgy work around, but it doesn't run any callbacks:

Post.all(:user_id => post.user_id, :type => post.type).destroy!

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket