<?php
class Email extends AppModel {

    var $name = 'Email';


    var $recursive = 1;


    var $actsAs = array('Containable');

    var $order = "Email.udate DESC";

    var $hasMany = array(
	    'EmailAttachment' => array('className' => 'EmailAttachment',
			    'foreignKey' => 'email_id',
			    'dependent' => true,
			    'order' => 'EmailAttachment.size DESC',
			    'counterCache'=>'email_attachment_count'),

	    'EmailRecipient' => array('className' => 'EmailRecipient',
			    'foreignKey' => 'email_id',
			    'dependent'=>true)

    );

    //Email 'From' this user.
    var $belongsTo = array(
	    'User' => array('className' => 'User',
			    'foreign_key'=>'user_id')
    );



    var $hasAndBelongsToMany = array (
	    'Enquiry' => array('className' => 'Enquiry',
			    'joinTable' => 'emails_enquiries'
	    ),
	    'Invoice' => array('className' => 'Invoice',
			    'joinTable' => 'emails_invoices'
	    ),

	    'PurchaseOrder' => array('className' => 'PurchaseOrder',
			    'joinTable' => 'emails_purchase_orders'
	    ),
	    'Job' => array('className' => 'Job',
			    'joinTable' => 'emails_jobs'
	    )
    );

    function getEnquiryEmails($id) {
	
		return $this->find('first', array('Enquiry.id'=>$id));
    }




}
?>
