What you need is a third Model say Transactions in place of your
activities_employees table.
And since I also have the Transaction Model I can store and use the
model as if it were like any other.

Your transactions will have

id
activity_id
employee_id
starttime
endtime
duration
notes


In your Employees and Activities when you set the associations you
would build up a $hasMany to 'Transactions' becase each employee/
activity has many transactions.
You will also setup a $hasAndBelongsToMany between Employees and
Activities specifying the "Transactions" table as the 'joinTable'
attribute.

My structure has four tables Employees, Activities, Jobs, Materials
that are all joined via the Transactions table in a hasMany as well as
a hasAndBelongsToMany.

In your new Transactions Model you will setup a belongsTo for each of
the tables you are using to map via the Transaction table (Employee
and Activity in your case).


Here is the definition of my Activity class

class Activity extends AppModel
{
    var $name = 'Activity';
    var $displayField = 'description';
        var $hasMany = array('Transaction' =>
                         array('className'     => 'Transaction',
                               'conditions'    => '',
                               'order'         => 'Transaction.created
DESC',
                               'limit'         => '5',
                               'foreignKey'    => 'activity_id',
                               'dependent'     => false,
                               'exclusive'     => false,
                               'finderQuery'   => ''
                         )
                  );
     var $hasAndBelongsToMany = array('User' =>
                               array('className'    => 'User',
                                     'joinTable'    => 'Transactions',
                                     'foreignKey'   => 'activity_id',
                                     'associationForeignKey'=>
'user_id',
                                     'conditions'   => '(1=1) group by
user_id',
                                     'order'        => '',
                                     'limit'        => '',
                                     'unique'       => true,
                                     'finderQuery'  => '',
                                     'deleteQuery'  => '',
                               ),
                               'Job' =>
                               array('className'    => 'Job',
                                     'joinTable'    => 'Transactions',
                                     'foreignKey'   => 'activity_id',
                                     'associationForeignKey'=>
'job_id',
                                     'conditions'   => '(1=1) group by
job_id',
                                     'order'        => '',
                                     'limit'        => '',
                                     'unique'       => true,
                                     'finderQuery'  => '',
                                     'deleteQuery'  => '',
                               )
                               );
}

On Feb 29, 11:46 pm, djkoell <[EMAIL PROTECTED]> wrote:
> I'm trying to write data to a HABTM relationship that has additional
> attributes on the join table.  Here's a view of the DB tables I've
> setup.
>
> activities
> =============
> id
> name
>
> activities_employees
> ====================
> activity_id
> employee_id
> hours
>
> employees
> ==================
> id
> name
>
> I'd like to be able to associate any number of employees with
> activities and track the amount of time they each spend on that
> activity.  Using scaffolding, I can get the ability to associate n
> employees to an activity and create additional associations between
> those employees and other activities.  However, my issue is I'm not
> sure how to write to the hours attribute on the activities_employees
> table.
>
> Thanks for any help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to