Ways to wrtie in Active Record |
While the documentation shows you can write code like:
Code: $this->db->where(); You can also write more clean code with a lot less typing like below: Code: $my_query = $this->db
PurdyDesigns Website Design, Development. Also Including Web Hosting. Print Media, server deployment and management, and more!
Depending on context, I sometimes find it cleaner, especially with long chains, to do something like this:
PHP Code: $this->db->select('')
I personally don't find chaining any clearer. For more complex queries I like blank lines between my select, join, order_by, etc statements for code clarity so chaining is not an option
Code: $this->db->select('');
What I usually do is start with the SQL I want to generate, e.g.:
Code: select a, b, c Then I transfer that to my model: PHP Code: $this->db->select(array('a', 'b', 'c')) 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. |
Welcome Guest, Not a member yet? Register Sign In |