datamapper

Datamapper, defining your own object methods, how?

So lets say I have a class like below class List include DataMapper::Resource property :id, Serial property :username, String def self.my_username return self[:username] end end list=List.create(:username=>,'jim') list.my_username When I run this it tells me that the method cannot be found, and on more investigation ...

CSV to DataMapper Import

This is probably very simple, but I'm quite new to ruby and active record. I've got a CSV dump of a database which I'm trying to import to a database using DataMapper. I'm having trouble understanding which type of relationships I should define in the models so that it matches what is defined CSV. Here's what data I've got from the CS...

Migrating procedural, antique CRUD code and proprietary DBMS to OO ORM on SQL

Please excuse my long-winded explanation, but I wanted to be as explicit as possible in the hopes of getting as much useful feedback on my situation as possible. You can skip to the questions at the bottom if you are impatient. Explanation At my current job, development is done in an antiquated language that is hard-wired to a proprie...

Associating two resources, that are already related

I have three classes that need to be related, and I'm not sure how to do it. The User class, is of course for a user, Game represents a game, GameTurn represents a turn in the game. Game belongs to a user, the user who initiated the game, and GameTurn belongs to a user, the user who played that turn. What I want to do is associate User...

Datamapper at dreamhost

Has anyone had success with Datamapper and Dreamhost? Anytime it makes a request to the database, I get the 500 internal server error. Dreamhost has no clue and isn't answering a support ticket. I have confirmed the gem is installed, and the connection is made. If I enter invalid connection credentials, passenger kicks out an error. ...

Using sinatra, how do I construct a proper DateTime value from 3 separate input boxes?

How do I take a numeric month, day and year from three separate text inputs and parse a proper value for my DateTime field in the db? ...

DataMapper, how to create multiple records?

My example datamapper class class Simple include DataMapper::Resource property :id, Serial property :uid, Integer end And I have an array id uid's I would like to add. items=[1,2,3,4,5,6,7,8,9,1,1,1,2,2,2,3] If I wanted to search for any of the id's in the array I would do something like Simple.all(:uid.in=>items) Is th...

DataMapper Associations, simple code, not working

I'm just begining to use DataMappers associations, just to test things out have a very simple table structure, and it's is borking. require 'dm-core' require 'dm-migrations' DataMapper.setup( :default, "sqlite3://#{Dir.pwd}/dbtest.db" ) class Account include DataMapper::Resource property :id, Serial has 1, :userp...

DataMapper Many-To-Many Association using Sinatra

I just stared learning Sinatra and DataMapper while building a simple blog. I seem to have encountered a problem getting my Many-To-Many association working. I'm trying to associate categories with posts. Upon creation of a post, the category association is not created. Here are my models: class Post include DataMapper::Resource ...

How do I work with checkboxes with DataMapper and Sinatra?

I'm trying to make a simple room management service. The rooms have these properties: class Room include DataMapper::Resource validates_is_unique :number property :id, Serial property :number, Integer property :guest, String property :status, Enum[ :free, :occupied ], :default => :free end Then I create a new room like th...

How can I load DataMapper objects in an SQLite database with data from a spreadsheet?

I have Ruby on Rails app using DataMapper, the database is SQLite, the app is hosted on Heroku. I would like to load the DataBase with data from a spreadsheet, however, I don't know the most efficient way...please help! As an example, let say I have a User model with fields: Name Age Birthday Hometown ...

Find by association (Datamapper)

I've got two models that look like this class Stage include DataMapper::Resource property :id, Serial belongs_to :staff end class Staff include DataMapper::Resource property :id, String, :key => true property :full_name, String property :email, String has n, :stages end I'm trying to find all Stages that hav...

Please decipher the following error message: "Multiple keys in #<KeywordUser @user_id=1 @keyword_id=2>"

jruby google app engine error message: Multiple keys in #<KeywordUser @user_id=1 @keyword_id=2> Models: (attempting to implement has and belongs to many relationship) class Keyword include DataMapper::Resource property :id, Serial # required for DataMapper property :name, String # A varchar type string, for short strings ...

Data Mapper API - unsure about organisation

Let's say we have "User" and a "Hotel" model classes. I'd use a User_Mapper and Hotel_Mapper to load/save/delete etc. I want to then have the user be able to mark their "favourite" hotels. In the database I have my user_favourite_hotels table which is a simple link table along with say a field for subscribing to hotel updates. When list...

Making a calendar with Sinatra

Well I don't actually want to make a calendar but I need a view for each day of the year which I guess is sort of the same. Say I have a view where you see e.g. "July 1st" in the top of the page and you have links to the day before and the day after. Beneath this there is a list of - in my example - rooms and they have different states -...

How to access old state values within datamapper observer?

I'm using dm-observer to observe my dm models, and I need to perform some actions based on state changes within the model. I've figured out that @state is used to store the updated state value, but I have not been able to figure out how to access the old state value. In the example below I've used "old_state", but obviously that does not...

Closing DataMapper DB connection

Hello, my rails application generates lots of small sqlite databases using DataMapper. After data saved, .sqlite-file must be uploaded on a remote server and destroyed locally. My question is how to make DataMapper close .sqlite db connection and free repo's memory? Application should generate many databases, so it's important to save ...

DataMapper association: How do I specify table name that contains the associated rows?

I am working with a database that is already in place and used by other applications. The people who designed the database did not use pluralized table names, so DataMapper chooses the wrong table name when following associations. For instance: class Foo has n :components # => the table name here should be COMPONENT, but datamapper ...

Is checking whether a DataMapper (or other ORM) model is persisted a code smell?

I've found myself starting to leverage checking persistence to get my models to 'work'. It seems convenient and correct to include a persistence check. On the other hand, it feels a little shady, as if I was being overly cautious or breaking the ORM abstraction in a small way. An example might be: class Shipment include DataMapper:Re...

Sinatra and Datamapper - inserting data to a one to many relationship table

I have the following. Each article has a title and a body and also up to three urls. I would want to store the urls in a different table. Therefore in my form, i've a field for the urls. However they are not working, only the article fields get entered into the database. how should i specify them? Could any kind soul help me out with thi...