i'd have a transactions table, which is made up of id, book_id, user_id,
checked_out, checked_in

When a checkout is made, create a  new row, date time in checked_out
when its checkedin, update the checked_in date.

Handle whether its in, or out, with some simple business logic:
if theres a checked_out date but no checked_in date, its not available to be
rechecked out
you could also put a due_date, and charge an overdue fee if checked_in is
after due_date.

The transaction table can tell you many things:
how many books does a single user have out at any given time?
how many times has a book been checked out?
how often is a particular title left overdue?
etc.



On Wed, Jan 19, 2011 at 5:52 PM, Ryan Schmidt <[email protected]>wrote:

> Am I thinking about this the wrong way?
>
> How would you manage a system with a table for users and tables for various
> resources and the need to track which users used which resources for how
> long (so that they can be billed for it)?
>
>
> On Jan 16, 2011, at 06:20, Ryan Schmidt wrote:
>
> > Consider a system modeling a library. There are users who can check out
> books. Logically we want to be able to create an association between a user
> and a book when they check that book out. And of course a book that's
> already checked out to a user cannot be checked out to a different user
> until it's returned. Naively, when a user returns a book, we might delete
> the association. But imagine I want to be able to answer questions like
> which users have ever checked out this book and when? Which books has this
> user ever checked out and when? What books did this user have checked out
> during May? And so on. Clearly, to answer these questions, association needs
> to remain in some form after one might otherwise have deleted it. How is
> this type of situation typically modeled in CakePHP? Is there sample code or
> a section in the book I should refer to for this?
> >
> > I imagine there would be a separate table (and model?) for checking out a
> book. It would have an autoincrement id, the book id, the user id, the
> checkout date, and the return date. What I'm not sure about is how much of
> that Cake will manage for me and how much I need to manage myself; whether
> such a table would replace, or be in addition to, a regular hasMany
> relationship, etc.
>
>
>
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to