datamapper

Ruby on Rails app on Google App Engine

Hey there! Can anyone point me how I could deploy my rails app to GAE? I've been reading about it, but it seems to be a fairly complicated task. I tried with the google-appengine gem, but its not a piece of cake either. Has there been any progress with the DataMapper adapter or I'll need to make changes to my models? I was hoping to s...

How do I separate datamapper observer class into a different file from the model class?

I'm running into an error when I try to split the dm-observer class into a separate file from my model class. Previously it worked fine if I put it all into a single file. # test_observer.rb require 'dm-observer' class TestObserver include DataMapper::Observer observe Test before :create do # does funky stuff end end ...

Datamapper "first" method is querying the whole relation

I'm using Datamapper 1.0 with sinatra and sqlite3 as backend. I have some devices, which have multiple locations, and I usually only want the latest location of a device. The problem is that the generated SQL for the above line will query all locations for the device not just the latest one (and a device can have 10-20k locations). Thi...

Why do my Datamapper Validation contexts disappear when I call them?

Given: class Foo include DataMapper::Resource property :title, String, :length => 255 validates_length :title, :in => (50..255), :allow_nil => false, :when => :long_title validates_length :title, :in => (5..50), :allow_nil => false, :when => :short_title end When I run: my_foo.valid? :long_title I get: Argume...

Zend Framework: Fill form with data from mapper

There is an example of getting data from form using mapper in official quickstart. But there is no example in the whole Internet of populating form with data from mapper (for usual edit action, for example). I usually do something like this (without using mapper and dbTable): class News_Model_Form_News extends Zend_Form { private $id ...

Zend Framework and Preventing Fat Controllers

Avoiding Fat Controller So I'm using Zend Framework and I have a question involving preventing fat controllers with one of my actions. Basically I am normalizing a CSV file into my database. This means that I have to get the feed and then use my model. The feed grabbing is just there to show how it works, but that is now an Action Hel...

Ruby : Datamapper don't insert in database.

I a have the following datamapper ressource : class Job include DataMapper::Resource storage_names[:default] = 'job' property :id, Serial property :at, Integer, :required => true, :min => 0 property :name, Float, :required => true, :default => 0 property :cpu, Float, :required => true, ...

Ambiguous Column Naming in Select List -- DataMapper for Ruby

In DataMapper, I have tables like this: Foo === id Integer other_columns Whatever Fuzz === id Integer other_columns Whatever For associations: class Fuzz has 1, :foo, :child_key => :id end When I call: Fuzz.first.foo DataMapper generates SQL like this: select raw_sql_.* from(SELECT "ID", "OTHER_COL...

Rails3 + Datamapper - concurrent database connections

Is it possible to use concurrent databases in one rails application? With AR I can use establish_connection method inside a model. Is it possible with datamapper? ...

Data Mapper for Child Objects

Hello, Assume we have a Customer class which has a complex property called Address. Something like this: public class Customer { public string Name { get; set; } public Address { get; set; } } I need to implement Data Mapper pattern to persist Customer objects to the database. Should I have something like CustomerDataMapp...

Find by filename rather than ID in data mapper class

I have an abstract data mapper class: <?php abstract class ADataMapper { abstract public function addNew($dataObj); abstract public function update($dataObj); abstract public function find($primaryKey); abstract public function delete($dataObj); } ?> In a sub-class of ADataMapper, I need to find a row by a column that ...

Datamapper - Find each client by project

Hi, I'd like to view each Project by Client, but unsure how to use Datamapper to get this information out. I have my relationships setup like this: class Client property :id, Serial property :name, String has n, :projects, :foreign_key => "company_id" end class Project include DataMapper::Resource property :id, Serial...

Debugging Stack Level too deep in Ruby

I have ruby program that is running into a stack level too deep (SystemStackError) error, ending on datamapper: from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/collection.rb:510:in `each' from /usr/local/lib/ruby/gems/1.8/gems/dm-core-1.0.0/lib/dm-core/query/conditions/comparison.rb:616:in `map' from /usr/local/lib/ruby...

How to extend DataMapper::Resource with custom method

I have following code: module DataMapper module Resource @@page_size = 25 attr_accessor :current_page attr_accessor :next_page attr_accessor :prev_page def first_page? @prev_page end def last_page? @next_page end def self.paginate(page) if(page && page.to_i > 0) @current_page = page....

Datamapper (Overzealous Edition), Codeigniter and Has Many Clarification

Firstly, I would like to just it out there that I am an ORM noob. I've never used an ORM in my life and have reached a point in my day-to-day developing that I need to do some crazy advanced relationships that I believe Datamapper Overzealous Edition can help me with as I am using Codeigniter. In my database I have the following tables;...

Using SQL function as a group by field in datamapper (ruby)

I'm trying to use a slightly more interesting GROUP BY cause than what seems to be supported out of the box by DataMapper. The query I want to generate looks something like this: SELECT SUM(downloads), SUM(uploads) FROM daily_stats GROUP BY YEARWEEK(date) I'd like to be able to just tell DataMapper something along these lines: DailyS...

Best way to handle 404 in Rails3 controllers with a DataMapper get

It's very simple, I want to handle a normal [show] request with a call to DataMapper like I did in Merb. With ActiveRecord I could have done this: class PostsController def show @post = Post.get(params[:id]) @comments = @post.comments unless @post.nil? end end and it handles the 404 by catching the resource's exceptions. ...

Sinatra, select from Datamapper pass to Haml

I'm doing a brief exercise, condensed below. The issue I'm having is that I'm able to pass a selection of all tickets, but not a selection of one ticket. At / there is no problem listing all the tickets, at endpoint for a ticket I get: NoMethodError at /pi2l9ulnw undefined method `slug' for # I'm relatively new to Ruby and cutting and ...

Datamapper, Sinatra, Haml : attaching and rendering Comments from a post

I have a model Ticket which has n Comments belonging to it (many to one relationship). The issue is that I can not render any of the comments nor does the form post the comments to the database. I can kinda sorta do this from irb. I can add comments to tickets.comments, but I cannot pull individual comments - I can pull up the collect...

Strange Datamapper's behaviour

I have this code in my controller: @cats = DirCat.all And this in a view: %ul#menu = @cats.each do |item| %li = link_to item.title, "/catalog/#{item.id}/" And get strange output: <ul id='menu'> <li> <a href="/catalog/4/">hello</a> </li> <li> <a href="/catalog/5/">hello 1</...