association_collection_tools 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -16,20 +16,21 @@ a. fast_copy
16
16
  A method called fast_copy is added to has_and_belongs_to_many association
17
17
  collections that makes the process of cloning HABTM associations *MUCH*
18
18
  more efficient. Simply replace person1.items = person2.items with
19
- person1.items.fast_copy(person2) and you're database, network and RAM will
19
+ person1.items.fast_copy(person2) and your database, network and RAM will
20
20
  thank you. See below for more details.
21
21
 
22
- b. ids
22
+ b. fast_add
23
+ fast_add operates just like fast_copy, but instead of replacing the existing
24
+ objects in the association, it appends new objects to the association.
25
+
26
+ c. ids
23
27
  A method called ids is added to has_many and has_and_belongs_to_many
24
28
  association collections. It returns the list of object ids in the association
25
29
  collection without unnecessarily instantiating the objects.
26
30
 
27
31
  == Installation
28
32
 
29
- 1. This plugin requires that the memcache-client gem is installed.
30
- # gem install association_collection_tools
31
-
32
- 2. Install the plugin OR the gem
33
+ 1. Install the plugin OR the gem
33
34
  $ script/plugin install svn://rubyforge.org/var/svn/zventstools/projects/association_collection_tools
34
35
  - OR -
35
36
  # gem install association_collection_tools
@@ -103,6 +104,12 @@ actually already exists and I'm just blind, but from the looks of
103
104
  http://dev.rubyonrails.org/ticket/2917, it appears that it is a
104
105
  documentation bug.
105
106
 
107
+ == HABTM Fast Add
108
+ fast_add operates just like fast_copy, but instead of replacing the existing
109
+ objects in the association, it appends new objects to the association.
110
+
111
+ person1.items.fast_add([1,2], {:user_id => user_id})
112
+
106
113
  == HABTM and has_many ids
107
114
  Return the list of IDs in this association collection without unnecessarily
108
115
  instantiating a bunch of Active Record objects. What good is the id of
@@ -73,7 +73,13 @@ module ActiveRecord
73
73
  def fast_copy(other_object,attributes = {})
74
74
  self.fast_clear
75
75
  other_object_assocation_ids = other_object.send(@reflection.name).ids
76
- return [] if other_object_assocation_ids.empty?
76
+ self.fast_add(other_object_assocation_ids, attributes)
77
+ end
78
+
79
+ # fast_add allows you to quickly add objects identified by an array
80
+ # of ids to a HABTM association.
81
+ def fast_add(ids,attributes = {})
82
+ return [] if ids.empty?
77
83
 
78
84
  column_names = [ @reflection.primary_key_name,
79
85
  @reflection.association_foreign_key ]
@@ -83,8 +89,8 @@ module ActiveRecord
83
89
  attribute_values << attributes[k]
84
90
  }
85
91
 
86
- @owner.connection.execute("REPLACE INTO #{@reflection.options[:join_table]} (#{column_names.join(",")}) VALUES #{other_object_assocation_ids.map{|aid| "(#{@owner.quoted_id},#{aid}#{attributes.empty? ? "" : ("," + attribute_values.join(','))})"}.join(",")}")
87
- return other_object_assocation_ids
92
+ @owner.connection.execute("REPLACE INTO #{@reflection.options[:join_table]} (#{column_names.join(",")}) VALUES #{ids.map{|aid| "(#{@owner.quoted_id},#{aid}#{attributes.empty? ? "" : ("," + attribute_values.join(','))})"}.join(",")}")
93
+ return ids
88
94
  end
89
95
 
90
96
  # Return the list of IDs in this association collection without
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: association_collection_tools
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-11-02
6
+ version: 0.0.2
7
+ date: 2006-11-03
8
8
  summary: Adds fast_copy method to has_and_belongs_to_many associations cloning associations much faster than the assignment operator. Adds ids methods to has_many and has_and_belongs_to_many associations for retrieving object ids without instantiating ActiveRecord objects.
9
9
  require_paths:
10
10
  - lib
@@ -40,13 +40,5 @@ extensions: []
40
40
 
41
41
  requirements: []
42
42
 
43
- dependencies:
44
- - !ruby/object:Gem::Dependency
45
- name: memcache-client
46
- version_requirement:
47
- version_requirements: !ruby/object:Gem::Version::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 1.0.3
52
- version:
43
+ dependencies: []
44
+