Hey all,

So I have a table Products where all the column names are prefixed by 
'products_'

I've tried to do the following

module FieldNamingConvention
  def self.call(property)
    'products_' + property.name.to_s
  end
end

DataMapper.repository(:default).adapter.field_naming_convention = 
FieldNamingConvention

but that doesn't seem to work.  Doing

> Product.properties.each do |p|
>   puts p.field
> end

prints out the names like it should, but selects don't work.  (I'm assuming 
Product.properties.field is the database column_name)
i've resorted to specifying it per property in the model, which works, but 
I'm wondering if there's a better way to do it.

Also, is there a way to specify the field_naming_convention on a "per 
model" basis?  All the tables in this DB have "#{tablename_}" prefixed to 
all the columns

I tried to do something like

class Product
  include DataMapper::Resource
  
  @field_naming_convention = lambda do |value|
    'products_' + value.to_s
  end
  
  property :id, Serial
  property :quantity, Integer

  ...

end

but that doesn't work either.

Thanks in advance for helping out a ruby newbie

-Tim

-- 
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/-/bqkPpxHXlxoJ.
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.

Reply via email to