Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Record with enum in a CPK cannot be destroyed #25

Open
solnic opened this issue May 17, 2011 · 4 comments
Open

Record with enum in a CPK cannot be destroyed #25

solnic opened this issue May 17, 2011 · 4 comments
Labels
Milestone

Comments

@solnic
Copy link
Contributor

solnic commented May 17, 2011

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!


Created by Xavier Shay - 2011-01-18 04:43:40 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1478

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

To be clear, no DELETE SQL is ever generated.

by Xavier Shay

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

I’ve fixed this 2-years old issue in my fork: https://github.com/solnic/dm-core/commit/6968c74521502b1490938dd0e1e513d3fc55f6f2 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.

by Piotr Solnica (solnic)

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

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.

by Xavier Shay

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

[bulk edit]

by Dan Kubb (dkubb)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant