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

173 views
Skip to first unread message

Johannes Held

unread,
May 15, 2012, 8:19:09 AM5/15/12
to datam...@googlegroups.com
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....@tdqmed.rails/gems/dm-core-1.2.0/lib/dm-core/model/property.rb:218:in `valid?'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:51:in `save_self'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1006:in `block in _save'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1222:in `run_once'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-core-1.2.0/lib/dm-core/resource.rb:1005:in `_save'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-core-1.2.0/lib/dm-core/resource.rb:405:in `save'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `block in save'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations/context.rb:16:in `in_context'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:40:in `save'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/gems/dm-validations-1.2.0/lib/dm-validations.rb:130:in `create'
/Users/jo/.rvm/gems/ruby-1....@tdqmed.rails/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

Message has been deleted

Johannes Held

unread,
May 15, 2012, 12:39:59 PM5/15/12
to datam...@googlegroups.com
If I remove dm-validations it works like a charm. Bug?

require "dm-core"

require "dm-validations"
require "dm-migrations"


class C

  include DataMapper::Resource

  property :id, Serial
  property :name, String, :required => true
  validates_uniqueness_of :name
  property :valid, Integer, :default => true
end


def setup
  DataMapper::Logger.new($stdout, :debug)
  DataMapper.setup(:default, 'sqlite::memory:')
  DataMapper.finalize
  DataMapper.auto_migrate!

  C.first_or_create(:name => "test", :valid => true)
end

if __FILE__ == $0
  setup
  puts C.all.map(&:name)
end

Johannes Held

unread,
May 16, 2012, 10:19:14 AM5/16/12
to datam...@googlegroups.com

… having a property named valid creates some getter and setters. Which in turn stab dm-validation’s valid. :-(

I rename my property. :-)

Reply all
Reply to author
Forward
0 new messages