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

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
  • 427
  • 1
  • 5
  • 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
  • 31,780
  • 20
  • 84
  • 118
2
votes
2 answers

One-to-one DataMapper association

I'm very new to DataMapper, and I'm trying to create models for the following scenario: I've got a number of users (with a user name, password etc.), who can also be players or referees or both (so Single Table Inheritance is not an option). The…
mwittrock
  • 2,871
  • 1
  • 17
  • 20
2
votes
1 answer

How should I protect mass-assignment in Sinatra app with Datamapper?

I have Link model in Sinatra app class Link include DataMapper::Resource has n, :views validates_presence_of :url, message: "You must specify a URL." validates_length_of :url, maximum: 4096, allow_blank: true, message:…
tomekfranek
  • 6,852
  • 8
  • 45
  • 80
2
votes
2 answers

Ruby datamapper - search in flag value

I have a user table (datamapper model) that has a column called permission which contains the bitmask value. property :permission, Flag[:perm1, :perm2, :perm3] I want to find all the users who have certain permissions, such as perm1 and perm2 so I…
JVK
  • 3,782
  • 8
  • 43
  • 67
2
votes
1 answer

How to use an aggregate in an order by in DataMapper?

I've got a simple class like: class Foo include DataMapper::Resource property :id, Serial property :bar, Text, lazy: false property :created_on, DateTime, default: lambda { |r,p| DateTime.now } end I want to select them, grouped by…
Jak S
  • 649
  • 6
  • 11
2
votes
0 answers

Datamapper Resource validation fails but errors is empty

Okay so this a very strange issue where I can't figure out why a model is being saved. I've recreated the data input exactly in another record (even established the relationships with the same records) and the duplicate record saves fine. When I go…
Gerard
  • 4,818
  • 5
  • 51
  • 80
2
votes
1 answer

How do I get the raw SQL from a DataMapper::Collection?

I'm using the latest versions of postgresql, ruby and datamapper. I create a query like so: collection = Entry.all(:id => 2..4, :text => /test/) collection is a DataMapper::Collection object. It's possible to get the DataMapper::Query object by…
le_me
  • 3,089
  • 3
  • 26
  • 28
2
votes
2 answers

Composite primary key is used only to access records but not save records in data_mapper

I have an app that tracks a player's progress over a fitness program. So every player has multiple weeks with the same :week_id Week_id combined with the belongs_to relationship is the composite primary key for the Week record. However, when I try…
JoeyC
  • 764
  • 11
  • 19
2
votes
0 answers

In Datamapper, getting "NoMethodError - undefined method `get!' for nil:NilClass:"

I have two tables, mapped out for datamapper: class User include DataMapper::Resource property :id, Serial, :field => 'ID' property :user_first_name, String, :field => "USER_FIRST_NAME" property…
Tom
  • 21
  • 1
2
votes
2 answers

Why datamapper does not update records / detect dirtiness?

I recently wanted to write a simple migration script. I wrote: @entries = Entries.all(:text => /test/) @entries.each do |entry| entry.update(:text => entry.text.gsub!(/test/, "no-test")) end It didn't save the records, even though the update…
le_me
  • 3,089
  • 3
  • 26
  • 28
2
votes
0 answers

Maintaining Many to Many relation with checkboxes (e.g. checkboxes for each category a post can be in)

We have a table with Categories containing unique categories. And our posts should link to any of these categories. I tried to add checkboxes for selecting the categories in the following manner: Add the checkboxes containing the categories in a…
Alessandro Vermeulen
  • 1,321
  • 1
  • 9
  • 28
2
votes
0 answers

How to write a (Ruby) DataMapper custom type based on MySQL VARBINARY

I want to use UUIDs as primary keys in my database and was recommended to use VARBINARY(16) as column type. I have the following so far: module DataMapper class Property class UUIDKey < String key true default proc {…
Parnas
  • 87
  • 5
2
votes
1 answer

How Ruby Datamapper can use different data storage in same app

I am using sinatra with datamapper and have more than one database, that I want to connect to and use them per my logic in the same app. I have my datamapper settings defined in a file, say app.rb #Default database dm = DataMapper.setup :default,…
JVK
  • 3,782
  • 8
  • 43
  • 67
2
votes
2 answers

data_mapper, attr_accessor, & serialization only serializing properties not attr_accessor attributes

I'm using data_mapper/sinatra and trying to create some attributes with attr_accessor. The following example code: require 'json' class Person include DataMapper::Resource property :id, Serial property :first_name, String …
umassthrower
  • 1,307
  • 1
  • 11
  • 15