datamapper

undefined method merge

merb datamapper seems to be broken. $ merb Loading init file from /home/kristian/workspace/ruby/nightly/config/init.rb Loading /home/kristian/workspace/ruby/nightly/config/environments/development.rb :size option is deprecated, use String with :length instead (/usr/lib/ruby/gems/1.8/gems/merb_datamapper-1.0.12/lib/merb/session/data_mapp...

How can I randomize DataMapper collection and convert it to JSON?

Hi, I'm pulling my hair out trying to build a little random photo JSON feed using DataMapper/Sinatra. Here's what I have so far.. Photo.favorites.to_json(:methods => [:foo, :bar]) So that works fine. The to_json method is provided in the dm-serializer library. All I want to do is randomize that feed so the photos don't show up in the...

Ruby & Datamapper checking if a record exists, and where?

I have a basic Ruby app that I am building with Sinatra, Datamapper and has user authentication using OAuth. When I receive the data back from the Oauth service, I save a record of a new user in an sqlite3 db. What I don't know how to do is how to go about verifying the user record doesn't already exist on the user database table. I ca...

DataMapper has n with conditions

Hello, By any chance is it possible to create a conditional association with DataMapper? For example: I want the User have n Apps just if that user have the attribute :developer => true something like this: class User include DataMapper::Resource property :id, Serial property :name, String, :nullable => false property :scre...

DataMapper has n through Resource DELETE (Remove from association) not working

Hi, I'm have this two classes class User include DataMapper::Resource property :id, Serial property :name, String has n :posts, :through => Resource end class Post include DataMapper::Resource property :id, Serial property :title, String property :body, Text has n :users, :through => Resource end So onc...

Master / Slave switch in the Zend Framework application layer

I am writing an application which requires the Master/Slave switch to happen inside the application layer. As it is right now, I instantiate a Zend_Db_Table object on creation of the mapper, and then setDefaultAdapter to the slave. Now inside of the base mapper classe, I have the following method: public function useWriteAdapter() { ...

Ruby Datamapper table inheritance with associations

I started learning Datamapper and what I liked about it was that I can write my models with real inheritance. Now I wonder, if it is possible to be more advanced about this: class Event include DataMapper::Resource property :id, Serial property :begin, DateTime property :type, Discriminator end class Talk<Event property :tit...

DataMapper w/o using reflection - how to implement?

I am creating some experimental OR/M library using all the "standard" patterns: UnitOfWork, IdentiryMap etc. I have created a skeleton and some functionality almost for all of the components, only DataMapper has left. My goal is to avoid reflection completely, I would like to rely only on AOP(PostSharp) and code generation. So the quest...

Autocomplete with Vim and Rails Datamapper

Is there a way that I can have auto completion in Vim after I load a model from the database? So for example if I have a model of type Foo with an instance method of type bar and do the following foo = Foo.first(:param=>'x') foo.b should show me bar as a possible auto complete value. I think that this is somewhat hard to accomplish wi...

Reading custom data from SQL tables

We have an application that allows the user to add custom columns to our tables (maybe not the best idea, but that's how it is). We are now (re)designing our dataaccess layer (we didn't really have one before) and now we're going to use parameterized queries in our datamappers when querying the SQL-database (earlier we concatenated the...

Problem install do_sqlite3 for DataMapper

sudo env ARCHFLAGS="-arch x86_64" gem install do_sqlite3 Building native extensions. This could take a while... ERROR: Error installing do_sqlite3: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb checking for sqlite3.h... yes checking for sqlite3_open() i...

How to fetch only specified fields of model with DataMapper?

Hello there! I cant find the way to fetch only necessary fields of model in certain context. Let`s say i have a huge model which has about 30 fields (properties). But for a search purpose i need only couple of them. Example: class Foo include DataMapper::Resource property :id, Serial property :title, String, :length => 256 p...

What does a Data Mapper typically look like?

I have a table called Cat, and an PHP class called Cat. Now I want to make a CatDataMapper class, so that Cat extends CatDataMapper. I want that Data Mapper class to provide basic functionality for doing ORM, and for creating, editing and deleting Cat. For that purpose, maybe someone who knows this pattern very well could give me some ...

Data Mapper: Is my interpretation correct?

I'm trying to confirm now, what I believe about the Data Mapper pattern. So here we go: Section A: A Data Mapper is a class which is used to create, update and delete objects of another Class. Example: A class called Cat, and a Data Mapper called CatDataMapper. And a database table called cats. But it could also be an xml file called ca...

Data Mapper and Relationships: Implementation strategies?

I've almost finished my Data Mapper, but now I'm at the point where it comes to relationships. I will try to illustrate my ideas here. I wasn't able to find good articles / informations on this topic, so maybe I'm re-inventing the wheel (for sure I am, I could just use a big framework - but I want to learn by doing it). 1:1 Relationshi...

Data Mapper: An domain object should never call its data mapper?

I'm reading Martin Fowler's Book about enterprise application architecture design patterns, but the German version. So, in my book on page 193 (in case you have it), he writes in German that a domain object (an object of the business logic layer) should not be depending on their Data Mapper. So what does that mean in more detail? If I ha...

How to load a one-to-many relationship in Data Mapper?

While I'll go for the Ghost pattern in a 1:1 relationship, I'm not sure if this is sufficient in a 1:n relationship. For example, when I load an Order object that may have a hundred Item objects, I would first assign NULL to the items property. The question is: A) Should I assign NULL and then, upon first access of the items property...

Should a Finder Method be part of the Data Mapper, or part of the domain class?

In Martin Fowler's Patterns for Enterprise Application Architectures book (page 229 in German, Lazy Load) he gives an example with this code: public List getProducts() { if (products == null) products = Product.findForSupplier(getID()); return products; } like you can see, the finder method seems to be part of the domain class...

Model & Mapper relationship

Hi there, I currently work on a small application with models, mappers and controllers. My question is, (because I did not found any matching answer), how does the mapper interact with the model (& the controller), when we have the following situation. $user = new UserModel(); $user->setId('21'); $userMapper = new UserMapper($user); $u...

Using Modules to Define Properties with Datamapper

Hi, so I'm setting up some models and they are based off of 2 abstract base classes (or rather they used to be classes). After running into a lot of trouble with Datamapper's handling of STI for my use case, which appears to be an open bug on their lighthouse page, I decided instead to just do modules to define all the properties to keep...