<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -513,15 +513,15 @@ module DataMapper
             end
         end
 
-        resource.instance_variable_set(:@repository, repository)
-        resource.instance_variable_set(:@saved,      true)
+        resource.instance_variable_set(:@_repository, repository)
+        resource.instance_variable_set(:@_saved,      true)
 
         if identity_map
           # defer setting the IdentityMap so second level caches can
           # record the state of the resource after loaded
           identity_map[key_values] = resource
         else
-          resource.instance_variable_set(:@readonly, true)
+          resource.instance_variable_set(:@_readonly, true)
         end
 
         resource</diff>
      <filename>lib/dm-core/model.rb</filename>
    </modified>
    <modified>
      <diff>@@ -50,12 +50,6 @@ module DataMapper
       model.extend Model
     end
 
-    # Collection this resource associated with.
-    # Used by SEL.
-    #
-    # @api private
-    attr_writer :collection
-
     # @api public
     alias_method :model, :class
 
@@ -68,8 +62,8 @@ module DataMapper
     #
     # @api semipublic
     def repository
-      # only set @repository explicitly when persisted
-      defined?(@repository) ? @repository : model.repository
+      # only set @_repository explicitly when persisted
+      defined?(@_repository) ? @_repository : model.repository
     end
 
     # Retrieve the key(s) for this resource.
@@ -83,7 +77,7 @@ module DataMapper
     #
     # @api public
     def key
-      return @key if defined?(@key)
+      return @_key if defined?(@_key)
 
       model_key = model.key(repository_name)
 
@@ -92,7 +86,7 @@ module DataMapper
       end
 
       # only memoize a valid key
-      @key = key if model_key.valid?(key)
+      @_key = key if model_key.valid?(key)
     end
 
     # Checks if this Resource instance is new
@@ -112,7 +106,7 @@ module DataMapper
     #
     # @api public
     def saved?
-      @saved == true
+      @_saved == true
     end
 
     # Checks if this Resource instance is destroyed
@@ -122,7 +116,7 @@ module DataMapper
     #
     # @api public
     def destroyed?
-      @destroyed == true
+      @_destroyed == true
     end
 
     # Checks if the resource has no changes to save
@@ -154,7 +148,7 @@ module DataMapper
     #
     # @api public
     def readonly?
-      @readonly == true
+      @_readonly == true
     end
 
     # Returns the value of the attribute.
@@ -377,8 +371,8 @@ module DataMapper
     def destroy!
       if saved? &amp;&amp; !destroyed?
         repository.delete(collection_for_self)
-        @destroyed = true
-        @readonly  = true
+        @_destroyed = true
+        @_readonly  = true
         reset
       end
 
@@ -490,7 +484,7 @@ module DataMapper
     #
     # @api semipublic
     def original_attributes
-      @original_attributes ||= {}
+      @_original_attributes ||= {}
     end
 
     # Checks if an attribute has been loaded from the repository
@@ -551,24 +545,40 @@ module DataMapper
     #
     # @api private
     def reset
-      @saved = false
+      @_saved = false
       identity_map.delete(key)
       original_attributes.clear
       self
     end
 
-    # Gets a Collection with the current Resource instance as its only member
+    # Returns the Collection the Resource is associated with
     #
-    # @return [Collection, FalseClass]
-    #   nil if this is a new record,
-    #   otherwise a Collection with self as its only member
+    # @return [nil]
+    #    nil if this is a new record
+    # @return [Collection]
+    #   a Collection that self belongs to
     #
     # @api private
     def collection
-      return @collection if (@collection &amp;&amp; @collection.query.conditions.matches?(self)) || new? || readonly?
+      return @_collection if (@_collection &amp;&amp; @_collection.query.conditions.matches?(self)) || new? || readonly?
       collection_for_self
     end
 
+    # Associates a Resource to a Collection
+    #
+    # @param [Collection, nil] collection
+    #   the collection to associate the resource with
+    #
+    # @return [nil]
+    #    nil if this is a new record
+    # @return [Collection]
+    #   a Collection that self belongs to
+    #
+    # @api private
+    def collection=(collection)
+      @_collection = collection
+    end
+
     protected
 
     # Method for hooking callbacks on resource creation
@@ -782,8 +792,8 @@ module DataMapper
 
       repository.create([ self ])
 
-      @repository = repository
-      @saved      = true
+      @_repository = repository
+      @_saved      = true
 
       original_attributes.clear
 
@@ -816,7 +826,7 @@ module DataMapper
         repository.update(dirty_attributes, collection_for_self)
 
         # remove the cached key in case it is updated
-        remove_instance_variable(:@key)
+        remove_instance_variable(:@_key)
 
         original_attributes.clear
 
@@ -996,7 +1006,7 @@ module DataMapper
     # @api private
     def run_once(default)
       caller_method = caller(1).first[/`([^'?!]+)[?!]?'/, 1]
-      sentinel      = &quot;@__#{caller_method}_sentinel&quot;
+      sentinel      = &quot;@_#{caller_method}_sentinel&quot;
       return instance_variable_get(sentinel) if instance_variable_defined?(sentinel)
 
       begin</diff>
      <filename>lib/dm-core/resource.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,8 +29,8 @@ module DataMapper
               attribute_set(name, blk.call(self))
             end
             save_self
-            @destroyed = true
-            @readonly  = true
+            @_destroyed = true
+            @_readonly  = true
             reset
           end
         RUBY</diff>
      <filename>lib/dm-core/types/paranoid_boolean.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,8 +28,8 @@ module DataMapper
               attribute_set(name, blk.call(self))
             end
             save_self
-            @destroyed = true
-            @readonly  = true
+            @_destroyed = true
+            @_readonly  = true
             reset
           end
         RUBY</diff>
      <filename>lib/dm-core/types/paranoid_datetime.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>64e17860781a3dc23ddc95cc6921324855d5535f</id>
    </parent>
  </parents>
  <author>
    <name>Dan Kubb</name>
    <email>dan.kubb@gmail.com</email>
  </author>
  <url>http://github.com/datamapper/dm-core/commit/337f9d050f4c24acc95861188dfc2e547e3161f0</url>
  <id>337f9d050f4c24acc95861188dfc2e547e3161f0</id>
  <committed-date>2009-11-06T14:07:38-08:00</committed-date>
  <authored-date>2009-11-06T14:07:38-08:00</authored-date>
  <message>Prefix all Resource internal ivars with an underscore

* This makes it less likely that user defined ivars will conflict
  with internal ivars used by DM.</message>
  <tree>5effe3172f39436da3fe3586df3dbe93f0aa18d6</tree>
  <committer>
    <name>Dan Kubb</name>
    <email>dan.kubb@gmail.com</email>
  </committer>
</commit>
