Questions tagged [ruby-datamapper]

DataMapper is a Object Relational Mapper written in Ruby. It implements an architectural pattern with the same name (with some changes).

Key features of Datamapper:

  • query chaining (delaying actual talking to a DB until necessary)
  • bulk loading of several data rows with one query
  • very abstract design allowing non-SQL adapters
  • lazy loading of large fields

Home page http://datamapper.org/

242 questions
2
votes
1 answer

DataMapper - Single Table Inheritance

Could Some one please explain to me what is going on here? This is an example that I put together to show y'all whats up: class Person include DataMapper::Resource property :id, Serial property :type, Discriminator property :name, String …
2
votes
1 answer

Has anyone created a web-app mix-in for Sinatra and Datamapper with Ruby?

I got sick of rewriting login forms and user account management pages with the usual use-cases of registering a new account, changing password, changing e-mail, w/ associated e-mails. (This is for clients that won't accept an OAuth/OpenID…
Lawrence I. Siden
  • 8,307
  • 10
  • 37
  • 49
2
votes
1 answer

How do you query based on a certain value in the child table using datamapper

create table foo (id, name) create table foo_config (id, foo_id, key, value) insert into foo (1, 'name1') insert into foo (2, 'name2') insert into foo (3, 'name3') insert into foo_config (1, 1, 'key1', 'val1') insert into foo_config (2, 1,…
Jason
  • 10,907
  • 18
  • 45
  • 66
2
votes
1 answer

How does the :save hook relate to the :update hook in DataMapper?

If I define the following model... class Foo include DataMapper::Resource property :name, String, :key => true before :save, do puts 'save' end before :update, do puts 'update' end end Why does the 2nd save also trigger the…
Larsenal
  • 45,294
  • 40
  • 140
  • 210
2
votes
1 answer

How to list possible Enum symbols in sinatra view?

Say I have a model like so: class Animal include DataMapper::Resource property :id, Serial property :type, Enum[ :cat, :bat, :rabbit, :zebra] end Assuming there is a route pointing to an erb template for adding more animals & @animal =…
Don Graziano
  • 431
  • 5
  • 15
2
votes
1 answer

DataMapper filter records by association count

With the following model, I'm looking for an efficient and straightforward way to return all of the Tasks that have 0 parent tasks (the top-level tasks, essentially). I'll eventually want to return things like 0 child tasks as well, so a general…
Joel
  • 2,525
  • 5
  • 32
  • 43
2
votes
3 answers

How can transactions be utilized in Ruby DataMapper?

I have a class that executes SQL statements (updates, inserts, and deletes) that are stored in a YAML file. I would like all the statements to be part of one transaction. If any of the SQL statements fail, then they would be rolled back. If all of…
programmingfun11
  • 133
  • 2
  • 10
2
votes
2 answers

Sinatra, DataMapper: No such table errors

Not sure why I am getting this error in my logs. This error happens every so often, but not consistently, and I'm not sure why. Here's my code: require 'rubygems' require 'sinatra' require 'data_mapper' DataMapper::Logger.new($stdout,…
Andrew
  • 196,883
  • 184
  • 487
  • 673
2
votes
3 answers

What's the most efficient way to iterate through an entire table using Datamapper?

What's the most efficient way to iterate through an entire table using Datamapper? If I do this, does Datamapper try to pull the entire result set into memory before performing the iteration? Assume, for the sake of argument, that I have millions…
Jason Marcell
  • 2,605
  • 5
  • 27
  • 39
2
votes
1 answer

Rails 3 + DataMapper - database not created/destroyed between tests

I'll try here since the mailing list for DM doesn't seem to have much input from other users unfortunately. I'm reasonably sure this isn't something we have to do manually, but maybe I'm wrong. I've removed ActiveRecord from my project and have…
d11wtq
  • 33,252
  • 14
  • 115
  • 186
2
votes
1 answer

Why is ActiveRecord inserting NULL in the type column of an STI model?

I'm working on porting a very large Rails project from DataMapper to ActiveRecord.  Among the models that has to be ported is a set of User models that used Single Table Inheritance (STI) to distinguish one type from another.  Here is a simplified…
2
votes
0 answers

Ruby DataMapper: order and/or filter query by computed value

Is there a way, using the DataMapper::Query::Conditions and DataMapper::Query::Direction object structures, to set a WHERE clause condition and/or an ORDER BY clause according to a computed value? In our User model, we have two date fields. Our…
2
votes
1 answer

DataMapper: one-to-many relationship with custom name?

I'm trying to build a small model consisting of two entities. For the purposes of this question, call them A and B. A has a one-to-many relationship to several Bs; this means that each B belongs_to an A. In this particular case, I'd like to call the…
Tim
  • 57,767
  • 18
  • 155
  • 161
2
votes
1 answer

How to add a WHERE clause in UPDATE query in Datamapper

I have a Datamapper model, say XYZ. Now, There are multiple threads which, at times, read a row using this model and attempt to update the same row - only one should should succeed, depending on a property of XYZ, say abc class XYZ include…
constantine1
  • 397
  • 1
  • 2
  • 12
2
votes
1 answer

ruby datamapper how to include child associations from has n association in query

Suppose I have an Article with n Comments. How would I go about grabbing all the comments with the article in one query with DataMapper? Something like the following false code: Article.get(:id).include(:comments).to_json I want the associated…
AJcodez
  • 26,232
  • 17
  • 72
  • 110
1 2
3
16 17