Recenty used Rails for $work, and came up this function to make it more convenient to retrieve remote records in a many-to-many relationship with a join-table used to saved the relationship and it'll takes a .map-conversion away to get the actual records.
Here's what we came up:
Project asynapse: http://code.google.com/p/asynapse/
Here's what we came up:
module AsynapseSupportIf your mixin this module in your ActiveRecord::Base, then you can say this in your user.rb model class:
def has_(prefix, item)
prefix = prefix.to_s
item = item.to_s
sy = "#{prefix}_#{item}"
mo = sy.camelcase.singularize
self.class_eval <
has_many :_#{sy}, :class_name => "#{mo}"
def #{sy}
_#{sy}.map { |f| f.#{item.singularize} }
end
EOE
end
end
has_ :favorite, :chatroomsIt'll make an favorite_chatrooms method to retrieve a list of "Chatroom" instead of retrieving a list of "FavoriteChatroom", which is the behaviour if you say:
has_many :favorite_chatroomsOur has_ method, although seems to be a controversial name, is pretty handy to deal with many-to-many relationship.
Project asynapse: http://code.google.com/p/asynapse/
- Location:opcafe
- Mood:busy
- Music:the postal office

