php - Can I preload belongsTo parent models in Laravel 4? -


I'm getting a big batch of 1000 scenes that I need to loop in my scene, I get them doing something like this I: $ children = child :: all ();

And in my opinion, I do something like this:

  @forach (children as $ $ children) {$ $ child- & Gt; Mother- & Gt; Name}} @ adverback   

The problem is, it executes 1000 queries. Do I have any way of using the relationship with related technique methods without this big loss of skill?

Yes, you have with :

  $ Children = child :: with ('parent') - & gt; all ();   

To get a original relationship, only one additional query should be started.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -