<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/models/authorship.rb</filename>
    </added>
    <added>
      <filename>db/migrate/20081018183748_create_authorships.rb</filename>
    </added>
    <added>
      <filename>test/fixtures/authorships.yml</filename>
    </added>
    <added>
      <filename>test/unit/authorship_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -7,7 +7,7 @@ class BooksController &lt; ApplicationController
   caches_page :index, :show, :if =&gt; Proc.new { |c| !c.request.format.html? }
   cache_sweeper :book_sweeper, :only =&gt; [:create, :update, :destroy]
   
-  @@private_book_attrs = [:id, :author_id]
+  @@private_book_attrs = [:id]
   
   def index
     @books = Book.list_books(params[:page], 20, :order =&gt; &quot;created_at DESC&quot;)</diff>
      <filename>app/controllers/books_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -93,6 +93,12 @@ module ApplicationHelper
   def author_page_link(author)
     link_to sanitize(smartypants(author.name)), author_path(author)
   end
+  
+  def author_pages_link(authors)
+    authors.map { |author|
+      link_to sanitize(smartypants(author.name)), author_path(author)
+    }.join(&quot;, &quot;)
+  end
 
   def page_turner(target, options = {})
     options.merge! :container =&gt; true, :page_links =&gt; false,</diff>
      <filename>app/helpers/application_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,8 @@ require 'urlify'
 
 class Author &lt; ActiveRecord::Base
   attr_accessible :name, :note
-  has_many :books
+  has_many :authorships
+  has_many :books, :through =&gt; :authorships
   before_validation :generate_permalink
   validates_presence_of :name, :permalink
   validates_uniqueness_of :name, :permalink
@@ -11,6 +12,7 @@ class Author &lt; ActiveRecord::Base
     
   # Lists all authors in the database.
   def self.list_authors(page, per_page, options = {})
+    options.merge!({:include =&gt; {:authorships =&gt; :book}})
     with_scope :find =&gt; options do
       paginate :per_page =&gt; per_page, :page =&gt; page
     end
@@ -29,4 +31,4 @@ class Author &lt; ActiveRecord::Base
       self.permalink = name.urlify
     end
   end
-end
\ No newline at end of file
+end</diff>
      <filename>app/models/author.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,11 +1,12 @@
 require 'urlify'
 
 class Book &lt; ActiveRecord::Base
-  attr_accessible :title, :comment, :cover_url, :isbn, :author_name
-  belongs_to :author
+  attr_accessible :title, :comment, :cover_url, :isbn, :author_names
+  has_many :authorships
+  has_many :authors, :through =&gt; :authorships
   before_validation :generate_permalink, :clean_isbn
   
-  validates_presence_of :title, :author, :permalink
+  validates_presence_of :title, :permalink, :authors
   validates_uniqueness_of :title, :permalink
   validates_format_of :cover_url,
                       :with =&gt; %r{\.(gif|jpg|png)$}i,
@@ -18,19 +19,24 @@ class Book &lt; ActiveRecord::Base
                       :message =&gt; &quot;must be a valid ISBN with 10 or 13 digits.&quot;
   
   def self.list_books(page, per_page, options = {})
+    options.merge!({:include =&gt; {:authorships =&gt; :author}})
     with_scope :find =&gt; options do
       paginate :per_page =&gt; per_page, :page =&gt; page
     end
   end
   
-  def author_name
-    author.name if author
+  def author_names
+    authors.map {|a| a.name}.join(&quot;, &quot;) if authors
   end
   
-  def author_name=(name)
-    self.author = Author.find_or_create_by_name(name) unless name.blank?
+  def author_names=(names)
+    self.authors = names.split(/\s*,\s*/).map do |name|
+      unless name.blank?
+        Author.find_or_initialize_by_name(name)
+      end
+    end
   end
-    
+  
   def clean_isbn
     self.isbn = self.isbn.gsub(/\D/, &quot;&quot;)
   end</diff>
      <filename>app/models/book.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,6 +23,8 @@ class BookSweeper &lt; ActionController::Caching::Sweeper
     expire_page &quot;/books/#{book.permalink}.xml&quot;
     
     expire_page &quot;/authors.xml&quot;
-    expire_page &quot;/authors/#{book.author.permalink}.xml&quot;
+    book.authors.each do |author|
+      expire_page &quot;/authors/#{author.permalink}.xml&quot;
+    end
   end
 end</diff>
      <filename>app/sweepers/book_sweeper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,7 @@
 &lt;% editable_content_wrapper :type =&gt; &quot;book&quot; do %&gt;
 	&lt;h2 class=&quot;title&quot;&gt;&lt;%= book_page_link(book) %&gt;&lt;/h2&gt;
 
-	&lt;p class=&quot;about clear&quot;&gt;&lt;%= edit_link(book) %&gt; By &lt;%= author_page_link(book.author) %&gt;, finished &lt;%= h(nice_date(book.created_at)) %&gt;&lt;/p&gt;
+	&lt;p class=&quot;about clear&quot;&gt;&lt;%= edit_link(book) %&gt; By &lt;%= author_pages_link(book.authors) %&gt;, finished &lt;%= h(nice_date(book.created_at)) %&gt;&lt;/p&gt;
 
 	&lt;%= content_tag :div, sanitize(smartypants(markdown(book.comment))), :class =&gt; &quot;comment&quot; unless book.comment.blank? %&gt;
 &lt;% end %&gt;</diff>
      <filename>app/views/books/_book.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -7,8 +7,8 @@
 	&lt;/div&gt;
 	
 	&lt;div class=&quot;section block wide&quot;&gt;
-		&lt;%= f.label :author_name, &quot;Author name&quot; %&gt;
-		&lt;%= f.text_field :author_name, :class =&gt; &quot;text&quot; %&gt;
+		&lt;%= f.label :author_names, &quot;Author names&quot; %&gt;
+		&lt;%= f.text_field :author_names, :class =&gt; &quot;text&quot; %&gt;
 	&lt;/div&gt;
 	
 	&lt;div class=&quot;section block wide&quot;&gt;</diff>
      <filename>app/views/books/_form.html.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4ca6156f66115e53a25318ab3e417812da9e5c91</id>
    </parent>
  </parents>
  <author>
    <name>Benedict Eastaugh</name>
    <email>benedict@eastaugh.net</email>
  </author>
  <url>http://github.com/ionfish/papertrail/commit/f56ee5afb1e2d6bdd1e48114ca16611137bc350e</url>
  <id>f56ee5afb1e2d6bdd1e48114ca16611137bc350e</id>
  <committed-date>2008-11-03T16:33:55-08:00</committed-date>
  <authored-date>2008-10-19T11:05:40-07:00</authored-date>
  <message>Add support for multiple authors</message>
  <tree>31d310f831ab3f3e9653ca8b292d826ddf778e82</tree>
  <committer>
    <name>Benedict Eastaugh</name>
    <email>benedict@eastaugh.net</email>
  </committer>
</commit>
