This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

maxDubovsky
maxDubovsky

Hi Friends,

I was working on the component that gets all states from the State model and later on gets all Cities of the state.

Component:

public function onRun()
{
    $this->prepareVars();
    $states = $this->page['states'] = $this->loadStates();
}

protected function loadStates()
{
    $countryId = $this->property('locationCountryId');
    $states = State::orderBy('name', 'asc')->where('country_id', intval($countryId))->get();
    return $states;
}

default.htm

{% for state in states %}
    <h5>{{state.name}}</h5>
{% endfor %}

Since I need to render all cities for each state I was thinking I need to do following:

public function onRun()
{
    $this->prepareVars();
    $states = $this->page['states'] = $this->loadStates();

    $states->each(function($state){
        //Get all cities of the current state: 
    });
}

But it appears that states.cities already contains all cities for current state. Of course in the model I have "hasMany" relation. Maybe my question is lame but if I call a model with relation, doest it mean it gets all relation data ?
I also have much more bigger model in my project plugin, does it mean if I'm using Model->get() method it gets tonns of data with all relations?
Can I get only Models data without it's relations? Could you suggest some article or manual to read on this?

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.