I am trying to track which users have referred other users to signup
for my site.  I have the following models:

class TellFriend extends AppModel
{
        var $name = 'Tell Friends';
        var $belongsTo = 'User';
        var $hasMany = 'ReferEmail';
}

class ReferEmail extends AppModel
{
        var $name = 'Refer Email';
        var $belongsTo = 'TellFriend';
}

TellFriend contains the email that they tell a friend with.
ReferEmail contains only the email address and the id back to the
TellFriend as FKey.

Finally, I have a controller that uses those models to try to find the
relation between the refer emails and my Users:

class ReferralsController extends AppController {
        var $name = 'Referrals';
        var $uses = array('ReferEmail', 'User');

        public function index()
        {
                $refers = array();
                $allRefers = $this->ReferEmail->findAll();
                foreach($allRefers as $row) {
                        $refer  = 
$this->User->findByEmail($row['ReferEmail']['email'],
'User.email');
                        if($refer) {
                                $data = array($row['ReferEmail']['email'] => 
array($refer));
                                array_push($refers, $data);
                        }
                }
                $this->set(compact('refers'));
        }
}

The way I'm searching for this relation seems all wrong, its not
spitting back the right data, and I'm having a brain freeze, is there
a way to do this better in Cake?!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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