
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
end
class Post
include DataMapper::Resource
property :id, Serial, :key => true
property :type, Enum[:a, :b], :key => true
property :title, String
belongs_to :user
end
DataMapper.finalize
DataMapper.auto_migrate!
user = User.create(:posts => [{:type => :a, :title => "Post A"}, {:type => :b, :title => "Post B"}])
user.reload
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
-
-
Piotr Solnica (solnic) January 20th, 2011 @ 02:33 AM
- State changed from unconfirmed to confirmed
- Milestone set to 1.1
- Assigned user set to Piotr Solnica (solnic)
- Milestone order changed from 196330 to 0
-
Piotr Solnica (solnic) January 20th, 2011 @ 03:50 AM
I've fixed this 2-years old issue in my fork: https://github.com/solnic/dm-core/commit/6968c74521502b1490938dd0e1... I know that Dan didn't want that change some time ago, but I think it's required and valid to do given the new Property system that's coming along.
-
Xavier Shay January 20th, 2011 @ 09:01 PM
Confirm that this fixes my issue.
I needed to change line 128 of spec/semipublic/model_spec to:
DataMapper.auto_migrate! if DataMapper.respond_to?(:auto_migrate)In order to run the spec against the in_memory adapter. I also tested on postgres.
-
Piotr Solnica (solnic) March 8th, 2011 @ 02:16 AM
- Milestone changed from 1.1 to 1.1.1
- Milestone order changed from 9 to 0
-
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »