How do I rename a column for a has 1 relationship for my legacy
database?
I have two tables in a legacy database.
AttributeName
ID
Name
Description
ArtworkAttribute
ArtworkID
AttributeID
Value
It's a simple relationship between a attribute (value) and the actual
attribute itself. I want to be able to do
ArtworkAttribute.AttributeName.Name. It always gives me Unknown column
'attribute_id' in 'field list'.
Is this th right way to specify it?
--- code
class ArtworkAttribute
include DataMapper::Resource
storage_names[:default] = "artworkattributes"
property :ID, String, :key => true
property :ArtworkID, Integer, :field => "ArtworkID"
property :AttributeID, Integer, :field => "AttributeID"
property :Value, Integer
has 1, :AttributeName, :child_key => :AttributeID
def to_s
self.AttributeName.Name + "=" + self.Value
end
end
class AttributeName
include DataMapper::Resource
storage_names[:default] = "attributenames"
property :ID, String, :key => true
property :Name, String
property :Weight, Integer
property :Description, String
property :Public, Boolean
def to_s
self.ID + ": " + self.Name + " (" + self.Description + ")"
end
end
---- running
ArtworkAttribute.all(:limit => 10)
Main.rb:81:in `process_arguments': Unknown column 'attribute_id' in
'field list' (DataObjects::SQLError)
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-do-adapter-1.0.2/lib/dm-
do-adapter/adapter.rb:142:in `read'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-do-adapter-1.0.2/lib/dm-
do-adapter/adapter.rb:260:in `with_connection'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-do-adapter-1.0.2/lib/dm-
do-adapter/adapter.rb:138:in `read'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
repository.rb:162:in `read'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
collection.rb:1116:in `lazy_load'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
associations/one_to_many.rb:280:in `lazy_load'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
support/lazy_array.rb:277:in `to_a'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
collection.rb:273:in `first'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
associations/one_to_one.rb:19:in `get'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
resource/state.rb:17:in `get'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
resource/state/persisted.rb:9:in `get'
from C:/Ruby/lib/ruby/gems/1.8/gems/dm-core-1.0.2/lib/dm-core/
model/relationship.rb:337:in `AttributeName'
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.