Skip to content

Commit

Permalink
Fixes a bug related to attribute's default values.
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Oct 28, 2010
1 parent 88f003c commit 1a723cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/dbagile/core/schema/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ class SchemaSemanticsError < DbAgile::SchemaError
TargetKeyMismatch
]
MESSAGE_VALUES = [
'invalid default value on attribute #{schema_object.name}',
'invalid default value \'#{schema_object.default_value}\' on #{schema_object}',
'relvar #{schema_object.relation_variable.name} has an empty heading (unsupported so far)',
'relvar #{schema_object.name} has no primary key',
'invalid constraint #{schema_object.name} on #{schema_object.relation_variable.name}',

'invalid index #{schema_object.name}',

'no such relvar #{args[:relvar_name]}',
'no such attributes #{args[:attributes].join(\',\')}',
'no such candidate key #{args[:constraint_name]}',
Expand Down
13 changes: 11 additions & 2 deletions lib/dbagile/core/schema/logical/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def default_value
def mandatory?
!(definition[:mandatory] == false)
end

def relvar
parent.parent
end

############################################################################
### Dependency control
Expand All @@ -38,7 +42,7 @@ def dependencies(include_parent = false)

# @see DbAgile::Core::Schema::SchemaObject
def _semantics_check(clazz, buffer)
unless default_value.nil? or default_value.kind_of?(domain)
unless default_value.nil? or (domain === default_value)
buffer.add_error(self, clazz::InvalidDefaultValue)
end
end
Expand All @@ -54,13 +58,18 @@ def to_yaml(opts = {})
out.map("tag:yaml.org,2002:map", :inline ) do |map|
map.add('domain', defn[:domain].to_s)
map.add('mandatory', false) unless defn[:mandatory]
if defn[:default]
unless defn[:default].nil?
map.add('default', defn[:default])
end
end
}
end

# Returns a string representation
def to_s
"Attribute #{relvar.name}::#{name} #{definition.inspect}"
end

end # class Attribute
end # module Logical
end # module Schema
Expand Down

0 comments on commit 1a723cb

Please sign in to comment.