Loans

**NOT READY YET: JUST FOR CODE VOYEURISM**
OMG!! love this process! Talking about this is fun!!!

Any way, in the console...when I create a loan with Loan.create(book_id:
book.id, user_id: user.id), book and user don't have references to each
other in user.books and book.user, respectively. I had the same issue with
book_authors. however, if you use the shovel, all of the parts are put
together auto-magically. Try it out in the console.

Well, after reviewing this...the way you suggested works! and now I realize
why!!!!!!!!!

Previously, I was using Loan.new(blahblah) ( and Book_Author.new(blah) ). I
was thinking in the java mind-set not ruby-rails!! CAUSE DATABASE!!!!!
Anyway, thanks for learning me good! I'll update this and create a ticket
to fix the way I've done book_authors!

I really REALLY love learning how to do things the right way. TBH the
shovel method felt hack-y to me, but I didn't really get the difference
btwn .new and .create until recently.

P

On Wed, Nov 26, 2014 at 12:47 PM, cheri allen <notifications@github.com>
wrote:

> In app/models/loan.rb:
>
> > @@ -0,0 +1,32 @@
> > +class Loan < ActiveRecord::Base
> > +  belongs_to :book
> > +  belongs_to :user
> > +
> > +  after_create :set_lending_info
> > +
> > +  DURATION = 30
> > +
> > +  def self.loan_book(book, user)
> > +    book.users << user
>
> Why is this happening instead of Loan.create(book_id: book.id, user_id:
> user.id) ? This seems like maybe it's fighting against Rails convention.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/cherimarie/LibraryCollection/pull/36/files#r20963043>.
>