Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Retrieving Records Based On Field In Related Model?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Victor Musvibe  
View profile  
 More options Feb 16, 7:19 am
From: Victor Musvibe <jaahvi...@gmail.com>
Date: Sat, 16 Feb 2013 04:19:05 -0800 (PST)
Local: Sat, Feb 16 2013 7:19 am
Subject: Retrieving Records Based On Field In Related Model?

I have an employees table with status that is active, new and resigned. In
my drop down menu for the application i have all 3 different statuses that
is active, new and resigned,now i wanna link to each different status, that
is when i click on active it only shows me the active users in the employee
table.

Please not status table is linked to the employees table.

Thank you in advance.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lowpass  
View profile  
 More options Feb 16, 2:01 pm
From: lowpass <zijn.digi...@gmail.com>
Date: Sat, 16 Feb 2013 14:01:54 -0500
Local: Sat, Feb 16 2013 2:01 pm
Subject: Re: Retrieving Records Based On Field In Related Model?
Run the find on the associated model.

I'm assuming that your statuses table has a 'name' column. Adjust as necessary.

In the Employee model:

public function fetchByStatus($status)
{
        return $this->Status->find(
                'all',
                array(
                        'conditions' => array'Status.name' => $status),
                        'recursive' => 0     // or 1
                )
        );

}

or:

public function fetchByStatus($status)
{
        return $this->Status->find(
                'all',
                array(
                        'conditions' => array'Status.name' => $status),
                        'contain' => array(
                                'Employee'
                        )
                )
        );

}

In the EmployeesController:

$data = $this->Employee->fetchByStatus($status);

Note that if you might in the future include a status that is not
URL-friendly, (eg. "A Multi-word Status" it would be best to create a
slug column instead of passing the name to the controller.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »