Hi,

I'm not a PHP developper, and I'm quite new to DataMapper, but I'm
pretty sure this is not the right approach. I believe you should use
the hooks (aka callbacks or events) to make this kind of process. The
reference is here http://datamapper.org/doku.php?id=docs:hooks, and
your code should look like this:

class Interest
  include DataMapper:Resource
   # properties
   property :user_id, Integer, :key => true
   property :question_id, Integer, :key => true
   property :interested_users, Integer, :default => 0
   timestamps :at

   # associations
   belongs_to :user, :child_key => [:user_id]
   belongs_to :question, :child_key => [:question_id]

   # hooks
   before :save, :add_one

   protected
     def add_one
       self.interested_users = self.interested_users + 1
     end
end

I believe the hooks are called inside a transaction, so it should be
safe to do this. I used "interested_users" as Integer just to
illustrate, but you can fix it according to your needs.

Unfortunately the documentation is very scarce, I hope to have some
time to help fix that in the near future. Hope this helps.

Cheers,
Rafael
www.rafaelrosafu.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to