Johannes Held | 15 May 14:19
Picon

valid? raises error: wrong number of arguments (1 for 0)

I have a model named Fact. A fact belongs to many other models and holds some attributes. Think of it as a data-warehouse fact table.

class Fact

  include DataMapper::Resource

  belongs_to :patientposition, :key => true
  belongs_to :controlpointcount, :key => true
  belongs_to :radiationtype, :key => true
  belongs_to :collimatormovement, :key => true
  belongs_to :beamcount, :key => true
  belongs_to :marctype, :key => true

  property :valid, Boolean, :required => true, :default => true
  property :marctestdate_count, Integer, :required => true, :default => 0
  property :realvortest1_count, Integer, :required => true, :default => 0

  timestamps :at
end

All of the other models are described in the same way:
class Name
  include DataMapper::Resource
  property :id,  Serial
  property :value, String, :required => true
  validates_uniqueness_of :value
end

If I want to first_or_create a fact issuing e.g.
Fact.first_or_create("patientposition_id"=>2, "controlpointcount_id"=>3, "radiationtype_id"=>1, "collimatormovement_id"=>1, "beamcount_id"=>4, "marctype_id"=>3)

I get this error (which renders me helpless):

wrong number of arguments (1 for 0)
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-core-1.2.0/lib/dm-core/model/property.rb:218:in `valid?'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-validations-1.2.0/lib/dm-validations.rb:51:in `save_self'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1006:in `block in _save'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1222:in `run_once'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1005:in `_save'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P8zuGxh1EmCw@public.gmane.org/gems/dm-core-1.2.0/lib/dm-core/resource.rb:405:in `save'
/Users/jo/.rvm/gems/ruby-1.9.3-p194 <at> tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `block in save'
/Users/jo/.rvm/gems/ruby-1.9.3-p194 <at> tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations/context.rb:16:in `in_context'
/Users/jo/.rvm/gems/ruby-1.9.3-p194 <at> tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `save'
/Users/jo/.rvm/gems/ruby-1.9.3-p194 <at> tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:130:in `create'
/Users/jo/.rvm/gems/ruby-1.9.3-p194-VLRALfKXI8P3fQ9qLvQP4Q@public.gmane.orgils/gems/dm-core-1.2.0/lib/dm-core/model.rb:444:in `first_or_create'


This error appears whether I use the ids or the actual model instance queried from the database.

Any hints or ideas?

--
Johannes

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/RM8rfXCfCfgJ.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Clark Snowdall | 11 May 02:59
Gravatar

dynamic tables

Hello all,

I've dabbled in datamapper in the past, but don't have much experience
in it.  I'm trying to evaluate its usefulness for solving a problem I
have.

I have a number of tables (probably ~50) that I need to get data
from.  Each table has 5 columns in common.  Beyond those 5 columns
each table has various numbers of various other columns; none of them
in common with other tables.

I would like to find a means of ORM that would allow me to declare a
single model that could handle the basic 5 pieces of common data, but
then also access the extra columns dynamically depending on what table
was specified.  I would really prefer NOT to have to write 50 or so
models (especially since this number is being added to and subtracted
from in an ongoing fashion).  I was wondering if perhaps Datamapper
might be able to solve this in a clean dynamic way.

Thoughts anyone?

Thanks,
Snowdall

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Johannes Held | 3 May 08:19
Picon

What is the proper way to execute a SQL statement via DataMapper?

Hello list,

I’m wondering what's the proper way to execute a SQL statement via DataMapper.

Assume I these models are created at runtime:

class Bar
  include DataMapper::Resource
  property :id, :Serial
end

class Foo
  include DataMapper::Resource
  property :a, :Serial
  property :b, :Serial
  belongs_to Bar, :key => true
end

Now I want to create a view (and a model to mirror that view):
create view foo_count as
select a, b, count(bar) as count
from foo
group by a, b


How can I use DataMapper to execute this statement?
Is there a way to use the name system of DataMapper?

--
Cheers, Johannes

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/JboY90vrJl4J.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
jbrennan | 2 May 15:25
Picon
Gravatar

Listing all models in a repository (reflection)

I'm trying to whip up some debug pages based around all the models in my repository and I'm wondering if I can do this dynamically. Is there a way to list all the models in a given repository?


I'm not looking to list all the *objects* in the repo (not yet at least), but all the different kinds of models and their properties. I poked around the docs a little bit but was unable to find what I was looking for.

Any way to do this?

Thanks.

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/4BA_b0TnyzsJ.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Patrik Sundberg | 27 Apr 17:44
Picon
Gravatar

Mutex already locked error in pooling.rb (jruby/torquebox)

Hi,


I'm getting the following error at "random" times in an app I have deployed using jruby (1.6.7) on torquebox (2.0.1), using latest datamapper gems: https://gist.github.com/2507835

It's not something I can reproduce at will, seems to happen every few days under low load.

Anyone has an idea what's going on here? Bug in the pooling code?

Guessing jruby+TB may unearth some bugs under truly parallel threads not often encountered by most setups.

Thanks,
Patrik

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/WvVnnnRZMFYJ.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Neil C | 23 Apr 01:26

DataObjects::Postgres::Result

I executed a pure SQL query against Postgres using DataMapper and got an object of class DataObjects::Postgres::Result. However, I can't find any kind of documentation indicating how to manipulate this instance to get the data. Can you point me to that documentation?


Thanks.

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/bdmYgJHr454J.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Neil Chaudhuri | 21 Apr 07:30

Attributes on an Association

I need to store people, albums, photos, and the order that photos
appear in an album, so I decided to try adding a "position" attribute
to the association between Photo and Album. Consider the following
models:

class Person
  include DataMapper::Resource
...
end

class Album
  include DataMapper::Resource
...
  has n, :photos, "Photo", :through => :album_photos, :via => :photo
end

class Photo
  include DataMapper::Resource
...

  belongs_to :person, :required => true
  has n, :albums, "Album", :through => :album_photos, :via => :album
end

class AlbumPhoto
  include DataMapper::Resource

  property :position, Integer, :default => 1

  belongs_to :album, :key => true
  belongs_to :photo, :key => true

end

First, is such the right way to achieve this sort of thing? I didn't
see anything like this in the documentation.

To add a wrinkle, I have a model called Book which has a 1:M
relationship with Album. When I execute the following code

    album.album_photos.destroy
    album.album_photos << AlbumPhoto.new({:position =>3})
    book.update

I get "DataMapper::UpdateConflictError: Book#update cannot be called
on a dirty resource"

I am curious if my models are defined correctly. If so, how can I
delete all prior associations and update their positions "cleanly"?

Thanks.

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Fred | 18 Apr 23:18
Picon

Query Order

Guys,
how can I set the query (all, first, etc) order to something like
"ifnull(column1, column2) asc", I just can "order =>
[:column1.asc, :column2.asc]", but it does't work for null columns.
Thanks

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Jacob Basham | 13 Apr 19:18

Many to one association question

Howdy!


I have a very simple Many to One relationship

class InterviewGroup
  include DataMapper::Resource

  property :id, Serial
  has n, :interviews
end

class Interview
  include DataMapper::Resource

  property :id, Serial
  belongs_to :interview_group
  belongs_to :person
end

The problem is when I destroy an Interview, it deletes the parent InterviewGroup. Originally we had a :constraint => :destroy on InterviewGroup#interviews, removing the constraint still results in the InterviewGroup being destroyed. The odd thing is the related Person is not destroyed.

How would I go about fixing this so deleting an Interview will not destroy the Group?

Thanks!

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/ON-DKBy5s6gJ.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
Arthur MM | 9 Apr 20:26
Picon
Gravatar

decimal field using sqlite

hi, I am having some problem here with field Decimal

My Class:

require 'dm-core'

class Registry
  include DataMapper::Resource

  property :num, Decimal, :key => true,  :precision => 20, :scale => 0
end

require 'dm-migrations'
DataMapper.finalize
DataMapper.setup(:default, 'sqlite::memory:')
DataMapper.auto_migrate!

My Test:

// I start irb
$ irb -r ./dm
/home/arthur/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/yaml.rb:56:in
`<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your
ruby.

// and create a new registry
ruby-1.9.3-p0 :001 > r = Registry.new(:num => 321512420108210029)
 => #<Registry @num=#<BigDecimal:9771c54,'0.3215124201 08210029E18',
18(27)>>  // bigdecimal is showing correct num
ruby-1.9.3-p0 :002 > r.save
 => true
ruby-1.9.3-p0 :003 > Registry.all
 => [#<Registry @num=#<BigDecimal:98358e8,'0.3215124201 08210048E18',
18(27)>>] // num is wrong
ruby-1.9.3-p0 :004 >
Registry.all.first.num.to_i                                                             //
trying to convert to int
 =>
321512420108210048                                                                                          //
wrong value
ruby-1.9.3-p0 :005 >
BigDecimal.new(321512420108210029).to_i                                //
here, aparently bigdecimal is working correct
 => 321512420108210029

Anyone can help me ? What am I doing wrong ?
I try too on mysql, and I have the same problem.

Thanks

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Nikhil Prabhakar | 5 Apr 15:15
Picon
Gravatar

Call to DataMapper.auto_upgrade! doesn't return

Hi,

 I'm trying to setup a sinatra app on production server. In production environment, call to DataMapper.auto_upgrade! does not return. MySQL is running on a different server and I can connect to it via mysql command line as well as mysql gem. In an irb session I'm doing following steps to debug:

require 'rubygems'
require 'data_mapper'
require 'app/models/contact'
require 'environment'
DataMapper.setup(:default, Environment.get_db_conn_hash('production'))
DataMapper.auto_upgrade! # This call doesn't return.

Regards,
nipra

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/VTmaTFPj_GEJ.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Gmane