Welcome Guest, Not a member yet? Register   Sign In
Ways to wrtie in Active Record
#6

What I usually do is start with the SQL I want to generate, e.g.:

Code:
select a, b, c
from tablename
where a = 1

Then I transfer that to my model:

PHP Code:
$this->db->select(array('a''b''c'))
         ->
from('tablename')
         ->
where('a'1);

// and set my result to a variable or do something else with it:
$query $this->db->get(); 

In most cases, whether I choose chaining for a particular portion of the query depends on the complexity of that portion (e.g. if the interior of the select/where/etc. method spans multiple lines).

If part of my query is conditional, I've recently started leaning towards making additional calls to $this->db methods rather than using variables to set the arguments to those methods in a large chain, so I'm comfortable with both, but won't call $this->db multiple times unless using a single call requires jumping additional logic or variables.
Reply


Messages In This Thread
Ways to wrtie in Active Record - by Shawn P - 10-23-2014, 01:14 PM
RE: Ways to wrtie in Active Record - by Rufnex - 10-23-2014, 01:35 PM
RE: Ways to wrtie in Active Record - by peterdenk - 10-23-2014, 02:07 PM
RE: Ways to wrtie in Active Record - by mwhitney - 12-12-2014, 01:51 PM
RE: Ways to wrtie in Active Record - by bclinton - 12-12-2014, 05:08 PM
RE: Ways to wrtie in Active Record - by mwhitney - 12-15-2014, 10:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB