Veraticus / Dynamoid

Ruby ORM for Amazon's DynamoDB
http://joshsymonds.com/Dynamoid/
247 stars 83 forks source link

Field name for id hard-coded in ManyAssociation:<< #158

Open lisad opened 11 years ago

lisad commented 11 years ago

In the ManyAssocation module, the method to add an item to an association assumes that the item's id field is called ':id'. Shouldn't it use the key field defined when the table is set up?

My code:

class Plan
  include Dynamoid::Document
  table :name => :events_plans, :key => :plan_id, :read_capacity => 400, :write_capacity => 400

  belongs_to :event
end

In the console:

$  an_event.plans << new_plan

The dynamoid ManyAssociation code with the hardcoded :id in the 1st line of the method:

      def <<(object)
        source.update_attribute(source_attribute, source_ids.merge(Array(object).collect(&:id)))
        Array(object).each {|o| self.send(:associate_target, o)} if target_association
        object
      end
lisad commented 11 years ago

Note that I also tried to use the Rails3 ActiveRecord method "set_primary_key", but that seems not to be implemented in Dynamoid::Document.

(http://apidock.com/rails/ActiveRecord/AttributeMethods/PrimaryKey/ClassMethods/set_primary_key)

loganb commented 11 years ago

Hi Lisa,

That does, indeed sound like a bug. Any chance you can put together a pull request with a fix + the requisite spec?

lisad commented 11 years ago

I'm planning to contribute at some point but I'd like to get more of a feel for DynamoDB and Dynamoid first. I just started this week with both. We're also on a release deadline at work :)