Search Results

Search found 62 results on 3 pages for 'datamapper'.

Page 1/3 | 1 2 3  | Next Page >

  • What, *specifically*, makes DataMapper more flexible than ActiveRecord?

    - by Billy ONeal
    I'm comparing Doctrine 2 and Propel 1.5/1.6, and I'm looking in to some of the patterns they use. Doctrine uses the DataMapper pattern, while Propel uses the ActiveRecord pattern. While I can see that DataMapper is considerably more complicated, I'd assume some design flexibility comes from this complication. So far, the only legitimate reason I've found to use DataMapper over ActiveRecord is that DataMapper is better in terms of the single responsibility principle -- because the database rows are not the actual objects being persisted, but with Propel that doesn't really concern me because it's generated code anyway. So -- what makes DataMapper more flexible?

    Read the article

  • DataMapper Dates

    - by Ethan Turkeltaub
    Forgive me if this is a simple answer. But how do you get a Date from a DataMapper property. For example: require 'rubygems' require 'sinatra' require 'datamapper' class Test include DataMapper::Resource property :id, Serial property :created_at, Date end get '/:id' do test = Test.get(1) test.created_at = ? end

    Read the article

  • how do I migrate Datamapper on appengine

    - by Roy
    I've changed my model from class Place include DataMapper::Resource has n, :trails property :id, Serial property :name, String, :length => 140 property :tag, String, :required => true timestamps :at end to class Place include DataMapper::Resource has n, :trails property :id, Serial property :name, String, :length => 140 property :tag, String, :required => true property :trail_count, Integer, :default => 0 timestamps :at end I just added "property :trail_count, Integer, :default = 0" and i want to migrate the existing appengine table to have the extra field "trail_count" i've read that DataMapper.auto_upgrade! should do it. but i get an error "undefined method `auto_upgrade!' for DataMapper:Module" can you please help How do i migrate the DM models?

    Read the article

  • DataMapper save fails but with no errors

    - by Justin Bozonier
    When I try to modify and then save a model using DataMapper I get a SaveFailure exception but no errors. Specifically I see this message: "MonthlyBill#save returned false, MonthlyBill was not saved" This is the code doing the saving: post '/monthly_bills' do with_authenticated_user do |user| description = params[:description] expected_amount = params[:expected_amount] pay_period = params[:pay_period] monthly_bill = MonthlyBill.new(:description=>description, :expected_amount=>expected_amount, :pay_period=>pay_period) user.MonthlyBills << monthly_bill user.save end The User model: class User include DataMapper::Resource property :id, Serial property :email_address, String property :password, String has n, :MonthlyBills has 1, :CurrentPayPeriod end The MonthlyBill model: class MonthlyBill include DataMapper::Resource property :id, Serial property :description, String property :expected_amount,Decimal property :pay_period, Integer belongs_to :user end What is the issue and, more importantly, how can I get DataMapper to tell me more specifically what is wrong?

    Read the article

  • CodeIgniter & Datamapper as frontend, Django Admin as backend, database tables inconsistent

    - by Rasiel
    I created a database for a site i'm doing using Django as the admin backend. However because the server where the site is hosted on, won't be able to support Python, I find myself needing to do the front end in PHP and as such i've decided to use CodeIgniter along with Datamapper to map the models/relationship. However DataMapper requires the tables to be in a specific format for it to work, and Django maps its tables differently, using the App name as the prefix in the table. I've tried using the prefix & join_prefix vars in datamapper but still doesn't map them correctly. Has anyone used a combination of this? and if so how have the fixed the issue of db table names being inconsistent? Is there anything out there that i can use to make them work together?

    Read the article

  • Saving a 'Date' using DataMapper on AppEngine+JRuby

    - by Ryan Montgomery
    I have a a model as follows: class Total include DataMapper::Resource property :id, Serial property :amount, Float, :default => 0.00 property :day, Date belongs_to :calendar end I am trying to select a specific Total from the data-store. class Calendar include DataMapper::Resource property :id, Serial property :name, String has n, :totals def get_total_for(date) return Total.first(:day => date, :calendar => self) end end When I call get_total_for(DateTime.now) I receive the following error on the call to the data-store. java.lang.IllegalArgumentException: day: org.jruby.RubyObject is not a supported property type. Is Date not allowed for usage in AppEngine? Is this a DataMapper issue? I have tried changing the name of the :day property to something else (hoping it was just a name conflict) but it doesn't seem to matter. Thanks for any help you can provide.

    Read the article

  • Datamapper, defining your own object methods, how?

    - by Dublinclontarf
    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 that you can only define class methods(not object methods) and that class methods don't have access to objects data. Is there any way to have these methods included as object methods and get access to object data? I'm using Ruby 1.8.6 and the latest version of datamapper.

    Read the article

  • Rails 3 Nested Forms with datamapper

    - by jens freudenau
    i have two models: class MeetingPoint include DataMapper::Resource belongs_to :profile property :id, Serial property :lat, String end and class Profile include DataMapper::Resource has n, :meeting_points property :id, Serial property :distance, Text property :created_at, DateTime property :updated_at, DateTime end Now I create a form to edit the profile and the meeting_poing: = form_for @profile do |f| = f.text_field :distance = f.fields_for :meeting_points do |ff| = ff.text_field :lat = f.submit But when I want to save the values I get always the error: "undefined method `readonly?' for ["lat", "14.000"]:Array"

    Read the article

  • Datamapper In Memory Database

    - by Daniel Ribeiro
    It is easy to setup Datamapper with a Sqlite3 in memory database with: DataMapper.setup :default, 'sqlite3::memory:'. However, when testing, I'd like to destroy the whole in memory database after each test, instead of invoking automigrate! as a shortcut on dropping everything. Is it possible? Or is it enough to set the default repository to nil, and let the garbage collector dispose of it?

    Read the article

  • ruby/datamapper: Refactor class methods to module

    - by DeSchleib
    Hello, i've the following code and tried the whole day to refactor the class methods to a sperate module to share the functionality with all of my model classes. Code (http://pastie.org/974847): class Merchant include DataMapper::Resource property :id, Serial [...] class << self @allowed_properties = [:id,:vendor_id, :identifier] alias_method :old_get, :get def get *args [...] end def first_or_create_or_update attr_hash [...] end end end I'd like to archive something like: class Merchant include DataMapper::Resource include MyClassFunctions [...] end module MyClassFunctions def get [...] def first_or_create_or_update[...] end => Merchant.allowed_properties = [:id] => Merchant.get( :id=> 1 ) But unfortunately, my ruby skills are to bad. I read a lot of stuff (e.g. here) and now i'm even more confused. I stumbled over the following two points: alias_method will fail, because it will dynamically defined in the DataMapper::Resource module. How to get a class method allowed_properties due including a module? What's the ruby way to go? Many thanks in advance.

    Read the article

  • Postgres error with Sinatra/Haml/DataMapper on Heroku

    - by sevennineteen
    I'm trying to move a simple Sinatra app over to Heroku. Migration of the Ruby app code and existing MySQL database using Taps went smoothly, but I'm getting the following Postgres error: PostgresError - ERROR: operator does not exist: text = integer LINE 1: ...d_at", "post_id" FROM "comments" WHERE ("post_id" IN (4, 17,... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. It's evident that the problem is related to a type mismatch in the query, but this is being issued from a Haml template by the DataMapper ORM at a very high level of abstraction, so I'm not sure how I'd go about controlling this... Specifically, this seems to be throwing up on a call of p.comments from my Haml template, where p represents a given post. The Datamapper models are related as follows: class Post property :id, Serial ... has n, :comments end class Comment property :id, Serial ... belongs_to :post end This works fine on my local and current hosted environment using MySQL, but Postgres is clearly more strict. There must be hundreds of Datamapper & Haml apps running on Postgres DBs, and this model relationship is super-conventional, so hopefully someone has seen (and determined how to fix) this. Thanks!

    Read the article

  • Datamapper Clone Record w/ New ID

    - by BouncePast
    class Item include DataMapper::Resource property :id, Serial property :title, String end item = Item.new(:title = 'Title 1') # :id = 1 item_clone = Item.first(:id = 1).clone item_clone.save This does "clone" the object as described but how can this be done so it applies a different ID once the record is saved, e.g. #

    Read the article

  • DataMapper: Create new record or update existing

    - by John Topley
    Does DataMapper provide a convenient way to create a new record when none exists or update an existing one? I couldn't find anything in the API documentation. This is what I have at the moment which doesn't seem very elegant: foo = Foo.get(id) if foo.nil? foo = Foo.create(#attributes...) else foo.update(#attributes...) end foo.save

    Read the article

  • Classless tables possible with Datamapper?

    - by barerd
    I have an Item class with the following attributes: itemId,name,weight,volume,price,required_skills,required_items. Since the last two attributes are going to be multivalued, I removed them and create new schemes like: itemID,required_skill (itemID is foreign key, itemID and required_skill is primary key.) Now, I'm confused how to create/use this new table. Here are the options that came to my mind: 1) The relationship between Items and Required_skills is one-to-many, so I may create a RequiredSkill class, which belongs_to Item, which in turn has n RequiredSkills. Then I can do Item.get(1).requiredskills. This sounds most logical to me. 2) Since required_skills may well be thought of as constants (since they resemble rules), I may put them into a hash or gdbm database or another sql table and query from there, which I don't prefer. My question is: is there sth like a modelless table in datamapper, where datamapper is responsible from the creation and integrity of the table and allows me to query it in datamapper way, but does not require a class, like I may do it in sql?

    Read the article

  • DataMapper and Codeigniter - how to fully manage a many-to-many relationship

    - by user252160
    I have the following relationship CType has many Field Field has many Ctype and of course the tables used are fields, ctypes, and ctypes_fields. Normally, the ctypes_fields table should contain only ids referencing the other two tables. However, i'd like to put there a "options" field that will contain some content for the concrete instance only. I walked through all DataMapper tuts but I could'n find relevant info on how I could extract these specific values (the ones in the relation table) Should I create a separate model for this relation table or there is a clever way to do this ?

    Read the article

  • datamapper secondary key

    - by Luc
    Hello, I am using datamapper in a ruby application and I'm facing a problem I do not understand. I have a Appartment model and a Location model. An appartment is at a given location and several appartments can be at the same location. This typically described a 1-n relationship (I guess :-) ) My feeeling is that in the Appartement sql table I need a location_id but I do not want any Appartment pointers within the Location table. For me, Location should live on its own and should not reference appartment. In the Appartement ruby class, I have added: has n, Location but it then creates an appartment_id within the Location ruby class, which I do not want. Would you have any clue ? Thanks a lot, Luc

    Read the article

  • Datamapper has n relationship with multiple keys

    - by jing
    I am working on a simple relationship with DataMapper, a ruby webapp to track games. A game belongs_to 4 players, and each player can have many games. When I call player.games.size, I seem to be getting back a result of 0, for players that I know have games associated with them. I am currently able to pull the player associations off of game, but can't figure out why player.games is empty. Do I need to define a parent_key on the has n association, or is there something else I'm missing? class Game belongs_to :t1_p1, :class_name => 'Player', :child_key => [:player1_id] belongs_to :t1_p2, :class_name => 'Player', :child_key => [:player2_id] belongs_to :t2_p1, :class_name => 'Player', :child_key => [:player3_id] belongs_to :t2_p2, :class_name => 'Player', :child_key => [:player4_id] ... end class Player has n, :games ... end

    Read the article

  • DataMapper is only returning the last part of this query

    - by Josh K
    So I'm using the following: $r = new Record(); $r->select('ip, count(*) as ipcount'); $r->group_by('ip'); $r->order_by('ipcount', 'desc'); $r->limit(5); $r->get(); foreach($r->all as $record) { echo($record->ip." "); echo($record->ipcount." <br />"); } And I only get the last (fifth) record echo'ed out and no ipcount echoed. Is there a different way to go around this? I'm working on learning DataMapper (hence the questions) and need to figure some of this out. I haven't quite wrapped my head around the whole ORM thing.

    Read the article

  • After update hook not being called for DataMapper model with dm 1.0.2

    - by Macario
    Hi, I've the following model and I want to execute a method on save and update, problem is that the hook is not being executed on update. class User include DataMapper::Resource include BCrypt property :id, Serial property :email, String, :index => true property :crypted_password, String, :accessor => :private ... attr_accessor :password, :password_confirmation before :save, :encrypt_password! # also tried the following with no success: # before :update, :encrypt_password! # and tried this but hell was never raised # before :update do # raise 'hell' # end def encrypt_password! self.crypted_password = Password.create password end end This spec fails: it 'should call encrypt_password! on update' do subject.save.should be_true subject.should_receive(:encrypt_password!) subject.update(:password => 'other-password', :password_confirmation => 'other-password').should be_true end And this passes: it 'should call encrypt_password! on create' do subject.should_receive(:encrypt_password!) subject.save.should be_true end I've also tried with after :update in addition to after :save with no success. Am I missing something?

    Read the article

  • Set date format in ruby model (sinatra/datamapper)

    - by Gearóid
    Hi, I have a ruby model that contains a date attribue which I'd like to be able to pass in as a parameter in the format dd/MM/yyyy. However, my sqlite3 db stores the data in yyyy-MM-dd format so when a date like 20/10/2010 gets passed in, it will not be read to the database. I am using the Sinatra framework and using haml for the markup creation. Do I need to write a helper that takes the date string and converts it to the correct format for the db? Or can I set a format type on the models attribute? Thanks.

    Read the article

  • Anemic Domain Model, Business Logic and DataMapper (PHP)

    - by sunwukung
    I've implemented a rudimentary ORM layer based on DataMapper (I don't want to use a full blown ORM like Propel/Doctrine - for anything beyond simple fetch/save ops I prefer to access the data directly layer using a SQL abstraction layer). Following the DataMapper pattern, I've endeavoured to keep all persistence operations in the Mapper - including the location of related entities. My Entities have access to their Mapper, although I try not to call Mapper logic from the Entity interface (although this would be simple enough). The result is: // get a mapper and produce an entity $ProductMapper = $di->get('product_mapper'); $Product = $ProductMapper->find('[email protected]','email'); //.. mutaute some values.. save $ProductMapper->save($Product) // uses __get to trigger relation acquisition $Manufacturer = $Product->manufacturer; I've read some articles regarding the concept of an Anemic Domain model, i.e. a Model that does not contain any "business logic". When demonstrating the sort of business logic ideally suited to a Domain Model, however, acquiring related data items is a common example. Therefore I wanted to ask this question: Is persistence logic appropriate in Domain Model objects?

    Read the article

  • Can I check the validity of a single DataMapper property?

    - by Nathan Long
    In a custom DataMapper setter, I'd like to check whether the value I'm setting is valid or not. For instance: class ToastMitten include DataMapper::Resource property :id, Serial property :wearer, Enum['Chuck Norris', 'Jon Skeet'] property :first_worn_at, DateTime def wearer=(name) super if wearer.valid? # How can I do this? first_worn_at = Time.now end end end t = ToastMitten.new t.wearer = 'Nathan Long' # invalid value; do NOT set first_worn_at t.wearer = 'Jon Skeet' # valid value; set first_worn_at Can I check the validity of a single property like this without calling valid? on the object itself and looking through all the errors?

    Read the article

  • DataMapper: using auto_migrate! with many-to-many dependencies?

    - by pschuegr
    Hi, I'm trying to migrate my app from MySql to Postgresql, using Rails3-pre and the latest DataMapper. I have several models which are related through many-to-many relationships using :through = Resource, which means that DataMapper creates a join table with foreign keys for both models. I can't auto_migrate! these changes, because I keep getting this: ERROR: cannot drop table users because other objects depend on it DETAIL: constraint artist_users_owner_fk on table artist_users depends on table users constraint site_users_owner_fk on table site_users depends on table users HINT: Use DROP ... CASCADE to drop the dependent objects too. I have tried everything I can think of, and thought I had things working when I added :constraint = :skip to the field definition, but I keep getting that error back when I try and run auto_migrate. I thought that :skip meant that it would ignore the dependents, but maybe that only applies for deleting rows and not dropping tables? I should mention that I can run auto_migrate after i nuke the db once, but after that, errors. Any suggestions or advice much appreciated.

    Read the article

  • Strange DataMapper (0.10.2) error. Please help!

    - by Joel M.
    See the full error here: http://notesapp.heroku.com/ I'm using DataMapper and dm-validations 0.10.2. No matter how much I tweak my models, I get the same error, or another one. Here's how my model looks like: class User include DataMapper::Resource attr_accessor :password, :password_confirmation property :id, Serial, :required => true property :email, String, :required => true, :format => :email_address, :unique => true property :hashed_password, String property :salt, String, :required => true property :created_at, DateTime, :default => Time.now property :permission_level, Integer, :default => 1 validates_present :password_confirmation, :unless => Proc.new { |t| t.hashed_password } validates_present :password, :unless => Proc.new { |t| t.hashed_password } validates_is_confirmed :password

    Read the article

1 2 3  | Next Page >