On Apr 13, 4:48 pm, Rafael Cesar <[email protected]> wrote:
> Hey.. What's up guys..?
> I'm just beggining with Cake, and I'm still getting used to the MVC
> architecture...
> So.. right now I'm facing a "problem" and I really need your help..
>
> There's the thing.. I have the table
> Stores (id,name,city_id,...)
> Cities (id,state_id,name)
> States (id,name)
OK. And make sure your associations are correct.
model State:
var $hasMany = array('City');
model City:
var $belongsTo = array('State');
var $hasMany = array('Store');
model Store:
var $belongsTo = array('City');
> So.. What I want to do: Basically I want to get the Name of the store,
> the name of the city and the name of the state where the store is
> located...
>
> The problem is that using recursive level = 2 , I get much, much more
> data than I expect, overloading my server, because it lists the table
> People, with people from each city it lists..
> Using other levels, I just can get to the City name, but not the State
> name..
Yeah, recursive 2 can be a killer. If you really want to have some
fun, set debug to 3!
Anyway, try using ContainableBehavior. I've taken to including it in
my AppModel's $actsAs array because I use it so much.
model Store:
function fetchById($id = null)
{
return $this->find(
'first',
array(
'fields' => array('*'),
'conditions' => array(
'Store.id' => $id
),
'contain' => array(
'City' => array(
'State'
)
)
)
);
}
Debug the returned data to get a feel for how it's laid out.
> I've tryed using "expect", but I get some error messages and nothing
> seems to work...
You should never post to a list saying you have "some error messages"
without also including at least some of them. ;-)
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
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
To unsubscribe, reply using "remove me" as the subject.