Saturday, September 29, 2012

Re: Accessing extra fiends on many to many relationship table

If you need access to more data with in the joining table you will not be able to use a habtm model. You will need to change it into a has many model.

- "The cold winds are rising"

On Sep 29, 2012 9:06 PM, "gosukiwi" <fedekiller@gmail.com> wrote:
This is what I've got, I have a table named Users, and a table named Lessons, users can give lessons, and the can also suscribe to other user's lessons.
So my schema is something like this

users table
id  | username 
1   | mike

lessons table
id | name | teacher_id
1  | ...      |  1

So my users_lessons table looks something like this
user_id | lesson_id | confirmed
1          | 1             | false
2          | 1             | true
1          | 2             | false

So far I can map all the users from a lesson, and all the lessons from a user, but given a lesson, i cannot get the status of each user signed up to that lesson, how can I do that?

My Lesson model looks something like this

public $hasAndBelongsToMany = array(
        'Students' =>
            array(
                'className'              => 'User',
                'joinTable'              => 'users_lessons',
                'foreignKey'             => 'lesson_id',
                'associationForeignKey'  => 'user_id',
                'unique'                 => true,
                'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
            )
    );

--
Like Us on FacekBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

--
Like Us on FacekBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: