Model::find($conditions=null, $fields=null, $order=null, $recursive=null)
string $order; SQL ORDER BY conditions (e.g. "price DESC")
$this->User->Profile->findById("4", null, "Profile.dx")
and for the retrieve the State detail of the user, could use the variable $recursive=2 (or =3) in the model class.
2006/6/28, davide <[EMAIL PROTECTED]>:
Good afternoon.
I have 4 tables: users, states, profiles and profiles_users (model
extract at the end)
I would like to extract all users that has a particular profile.
Searching thought the list archive I found[1] the solution
$this->User->Profile->findById("4");
This works pretty fine but it doesn't sort the records and doesn't
retrieve the State detail of the user.
I would like to achieve the same result as of this query
select a.surname as surname, a.name as name,
c.dx as state, d.dx as profile
from users as a
join profiles_users as b on (b.user_id=a.id)
join profiles as d on (b.profile_id = d.id)
left join states as c on (a.state_id = c.id)
where b.profile_id = 4
and d.dt_end_val >= current_date
order by a.surname, a.name;
is there some cake-way for doing this or should I have to use the findBySQL?
Thanks in advance
Bye
Davide
1.
http://groups.google.com/group/cake-php/browse_thread/thread/50dd8e4461e34a81/8dbf01196906aaec
/*
* app/models/user.php
*/
class User extends AppModel{
var $name="User";
var $belongsTo = array("State");
var $hasAndBelongsToMany = array("Profile" =>
array(
"conditions " =>
"Profile.dt_end_val >= CURRENT_DATE",
"order" => "Profile.dx"
)
);
/*
* app/models/state.php
*/
class State extends AppModel{
var $name = "State";
var $displayField = "dx";
var $hasMany = array("User"=>array("limit"=>"5"));
/*
* app/models/profile.php
*/
class Profile extends AppModel{
var $name="Profile";
var $displayField = "dx";
var $hasAndBelongsToMany = array("User");
--
Ariel Santana
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
