Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Chained method calls are orthogonal to the ORM question, they're used all over the place in OOP. A chain-able method simply returns a reference to the current object, allowing the return value to be called. In PHP</p> <pre><code>class A { public function b() { ... return $this; } public function c($param) { ... return $this; } } $foo = new A(); $foo-&gt;b()-&gt;c('one'); // chaining is equivilant to // $foo = $foo-&gt;b(); // $foo = $foo-&gt;c(); </code></pre> <p>As for how queries are constructed, there are two methods. In ActiveRecord like ORMs there's code that examines the Database's meta-data. Most databases has some kind of SQL or SQL like commands to view this meta-data. (MySQL's <code>DESCRIBE TABLE</code>, Oracle's <code>USER_TAB_COLUMNS</code> table, etc.)</p> <p>Some ORMs have you describe your database tables in a neutral language such as YAML. Others might infer a database structure from the way you've created your Object models (I want to say Django does this, but it's been a while since I looked at it). Finally there's a hybrid approach, where either of the previous two techniques are used, but a separate tool is provided to automatically generate the YAML/etc. or class files.</p> <p>One the names and data-types of a table are known, it's pretty easy to pragmatically write a SQL query that returns all the rows, or a specific set of rows that meet a certain criteria.</p> <p>As for your last question, </p> <blockquote> <p>How does an ORM manage the queries while sustaining the arbitrary nature of all that is expected of it?</p> </blockquote> <p>I'd argue the answer is "not very well". Once you move beyond the one-table, one-object metaphor, each ORM has a different approach an philosophy as to how SQL queries should be used to model objects. In the abstract though, it's just as simple as adding new methods that construct queries based on the assumptions of the ORM (i.e. Zend_Db_Table's "findManyToManyRowset" method)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload