<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -131,14 +131,19 @@ are attempted in that order).
 For +select+, we also need an original collection -- basically, a list of all of
 the possible values -- to use with the list of selected values.  If the objects
 inside the collection are AR objects, then we take their class and issue a
-&lt;tt&gt;find(:all)&lt;/tt&gt; on it. For example, with this call:
+&lt;tt&gt;find(:all)&lt;/tt&gt; on it. If there are no available objects, then we attempt to
+reflect on the association for the given method to determine the right class.
+For example, with this call:
 
  f.field :collection_method
 
 If +collection_method+ returned a list of Post objects (or a single Post
 object), then we issue a &lt;tt&gt;Post::find(:all)&lt;/tt&gt; to determine the full
-collection (of selected and unselected values). This guessing can be overridden
-by passing the &lt;tt&gt;:collection&lt;/tt&gt; option with the desired collection.
+collection (of selected and unselected values). If an empty list is returned, or
+nil, then we look up the association for the object on +collection_method+ and
+try to invoke a &lt;tt&gt;find(:all)&lt;/tt&gt; on that class. This guessing can be
+overridden by passing the &lt;tt&gt;:collection&lt;/tt&gt; option with the desired
+collection.
 
 Note also that the set of selected items (or the single selected item) can be
 overridden by providing a collection or object to use instead through the</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -77,6 +77,9 @@ module AwesomeFields
     #   +to_s+ method, depending on whether the +name+ method exists or not.
     # * The full list of possible options will be derived by calling
     #   &lt;tt&gt;find(:all)&lt;/tt&gt; on the class of the first object of the collection.
+    #   If there is no object in the collection, then an attempt will be made to
+    #   find out the right class to call +find+ on by attempting to reflect on
+    #   the association represented by the method name (if any)
     # * The list of selected options (or the one selected option) will be
     #   derived by calling +method+ on the form object.
     #
@@ -104,10 +107,12 @@ module AwesomeFields
       selected = [ selected ] if ! selected.respond_to?(:first)
       reference_object = opts[:collection] ? opts[:collection].first \
                                            : selected.first
+      reference_class = (reference_object &amp;&amp; reference_object.class) ||
+                        @object.class.reflect_on_association(method).klass
 
       value_meth = opts[:value_method] || :to_param
       text_meth =  opts[:text_method]  || text_method_for(reference_object)
-      collection = opts[:collection]   || reference_object.class.find(:all)
+      collection = opts[:collection]   || reference_class.find(:all)
 
       all_values = collection.collect do |item|
         [ item.send(text_meth), item.send(value_meth) ]</diff>
      <filename>lib/awesome_fields/awesome_field_helpers.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2ebb2d71569434cebdc80e6054e1be7bd0d3fcdd</id>
    </parent>
  </parents>
  <author>
    <name>shadowfiend</name>
    <email>shadowfiend@ubuntu.Belkin</email>
  </author>
  <url>http://github.com/Shadowfiend/awesome_fields/commit/f3ecbc2be687a9958a1a048865bffe4712f19dc9</url>
  <id>f3ecbc2be687a9958a1a048865bffe4712f19dc9</id>
  <committed-date>2008-10-19T23:22:20-07:00</committed-date>
  <authored-date>2008-10-19T23:22:20-07:00</authored-date>
  <message>Added support for reflecting on associations for class determination in collection_field.

This allows us to use association reflection when there is no item in the list
of already-selected items to try and extract the class name from. That means we
can now correctly look up the full list for the collection field even when there
is nothing pre-selected -- useful for new fields in general.</message>
  <tree>56f8ffa733ac39d9b77fe27bf9c19430ac017e39</tree>
  <committer>
    <name>shadowfiend</name>
    <email>shadowfiend@ubuntu.Belkin</email>
  </committer>
</commit>
