Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:39:58+00:00 2026-06-18T10:39:58+00:00

Using Datamapper, I have a model Album that has n, :photos which has a

  • 0

Using Datamapper, I have a model Album that has n, :photos which has a Paperclip::Resource

With ActiveRecord I would just have had:

has_many :photos, dependent: :destroy

in my Album model, in order to delete the photos at the same time as the Album, but with Datamapper it seems you have to roll your own. In Sinatra, to delete the album I have:

delete '/albums/:id' do
  a = Album.get params[:id] 
  a.destroy
  redirect '/'
end

and a before filter in the Album model:

before :destroy do
  photos.destroy
end

but the before filter is never called.

If I put use the bang method, a.destroy!, the album is destroyed but not the Photos.

No errors are produced and no Exceptions raised.

UPDATE

There are errors, but with an empty errors hash:

INFO -- : #<DataMapper::Validations::ValidationErrors:0x13740dc @resource=#<Album @id=2 @name="Quaver" @created_at=#<DateTime: 2013-02-07T10:30:36+00:00 (5895194251/2400,0/1,2299161)> @updated_at=#<DateTime: 2013-02-07T10:30:36+00:00 (5895194251/2400,0/1,2299161)>>, @errors={}>

So clearly I have validation issues. However I have not set any validations in my Models:

class Photo  
  include DataMapper::Resource
  include Paperclip::Resource  

  property :id, Serial
  property :title, String
  property :created_at, DateTime  
  property :updated_at, DateTime

  has_attached_file :data, url: "/:attachment/:id/:style/:basename.:extension",
                       path: "#    {APP_ROOT}/public/:attachment/:id/:style/:basename.:extension"
  belongs_to :album
end

class Album  
  include DataMapper::Resource  
  property :id, Serial
  property :name, String
  property :created_at, DateTime  
  property :updated_at, DateTime
  has n, :photos

  before :destroy do
    photos.destroy
  end
end

So the before filter is not being called because of the ValidationErrors, but where do they come from when they are not explicitly set?

Any help, gratefully received. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:39:59+00:00Added an answer on June 18, 2026 at 10:39 am

    Apparently when you use:

    require 'data_mapper'
    

    you are implicitly using dm-constraints, which protects dependent models by default. Simply giving permission to destroy (much like ActiveRecord) does the trick:

    has n, :photos, constraint: :destroy
    

    Damn that hurt!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using DataMapper in a Rails project, and have found that calling to_json on
I have a padrino install that is using datamapper and logging queries to a
I'm using Datamapper v1.8.2 with Codeigniter v2.1.2 and have a get rule that doesn't
I have the following model in datamapper: class Student include DataMapper::Resource property :id, Serial
Just using DataMapper for the first time. I have set up a table in
I am using sinatra with datamapper and have more than one database, that I
I have found several examples using datamapper and was able to get them to
I am using the CodeIgniter DataMapper ORM, but there is something that I don't
I'm using DataMapper with the redis adapter in a Ruby library. I have these
I have a basic Ruby app that I am building with Sinatra, Datamapper and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.