
:required key word not enforced
Reported by thomas | July 10th, 2010 @ 12:13 PM
I'm running DM1.0 and sqlite3 adapter.
DM failed to enforce the :required field and allows nil value:
[root@linux-sapro2 dm.sqlite]# irb -r cmdb.rb
irb(main):001:0> @c = Cluster.create(:name =>
"cluster-1")
=> #
cmdb.rb
require 'rubygems'
require 'dm-aggregates'
require 'dm-core'
require 'dm-migrations'
require 'dm-types'
require 'dm-timestamps'
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/cm.db")
class Node
include DataMapper::Resource
property :id, Integer, :key => true, :required => true
property :name, String
property :descr, String
property :ipaddr, String
property :nodeid, String
belongs_to :cluster
end
class Cluster
include DataMapper::Resource
property :id, Integer, :key => true, :required => true
property :name, String
property :pub, Integer
has n, :node
end
DataMapper.auto_upgrade!
Comments and changes to this ticket
-
thomas July 10th, 2010 @ 12:16 PM
irb output was cut off, here is the rest:
[root@linux-sapro2 dm.sqlite]# irb -r cmdb.rb irb(main):001:0> @c = Cluster.create(:name => "cluster-1")
=> # -
thomas July 10th, 2010 @ 12:17 PM
- no changes were found...
-
-
thomas July 10th, 2010 @ 12:23 PM
- no changes were found...
-
thomas July 10th, 2010 @ 12:25 PM
shouldn't the ":key => true" enforce no-nil as well?
Currently, key fields are allowed nil values. Is this proper? -
Piotr Solnica (solnic) July 11th, 2010 @ 12:15 PM
- State changed from new to not-applicable
hey Thomas,
This is a correct behavior. In your example you want to use Serial property type probably, not Integer. Serial means that an object identifier will be generated by the datastore and returned to DataMapper via the datastore adapter.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »