Skip to content

Instantly share code, notes, and snippets.

@nathggns
Last active December 15, 2015 20:08
Show Gist options
  • Select an option

  • Save nathggns/5315862 to your computer and use it in GitHub Desktop.

Select an option

Save nathggns/5315862 to your computer and use it in GitHub Desktop.
Question about lazy-loaded models.

Question

In a lazy-loaded model, should all data be loaded from the database when asking for a value (SELECT * FROM ...), so there is only one db query, or just the value you asked for (SELECT value FROM...), so there is a db query for every value you ask for (cached).

Effiency, speed, and database load should all be considered.

Example Comparison:

All data:

PHP:

$id = $user->id;
$name = $user->name;

SQL:

SELECT * FROM users WHERE ...;

Just value

PHP:

$id = $user->id;
$name = $user->name;

SQL:

SELECT id FROM users WHERE ...;
SELECT name FROM users WHERE ...;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment