Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony and DQL syntax
    text
    copied!<p>I apologize for the beginner question, but I'm struggling with what seems should be a simple query. I can get it to work perfectly in MySQL, but can't get it to work in my symfony application. Essentially, this is all I'm trying to do:</p> <pre><code>SELECT * FROM benefits b WHERE b.company_id = X X = SELECT id FROM company c WHERE c.user_id = ($this-&gt;getUser()-&gt;getGuardUser()-&gt;getId()) </code></pre> <p>I've tried many join statements but still can't get it to work with the result I want, such as:</p> <pre><code>public function executeIndex(sfWebRequest $request) { $this-&gt;benefitss = Doctrine_Core::getTable('benefits') -&gt;createQuery('b') -&gt;where('user_id = ?', '$this-&gt;getUser()-&gt;getGuardUser()-&gt;getId()') -&gt;leftJoin('b.Company c') -&gt;andWhere('c.user_id = ?', '$this-&gt;getUser()-&gt;getGuardUser()-&gt;getId()') -&gt;execute(); } </code></pre> <p>Here's my condensed schema:</p> <pre><code>Benefits columns id user_id company_id name relations User {class: sfGuardUser} Company Company columns id user_id name relations User {class: sfGuardUser} sfGuardUser columns id </code></pre> <p>also of note: the user is not assigned a company_id b/c not all users will have companies according to my user definitions. </p> <p>Any help for this wretched beginner would be much appreciated. :) </p> <p>Update 8/27/11:</p> <p>This gets the results I want:</p> <pre><code>$this-&gt;benefitss = Doctrine_Core::getTable('benefits') -&gt;createQuery('b') -&gt;leftJoin('b.Company c') -&gt;Where('c.user_id = ?', '1') -&gt;execute(); </code></pre> <p>Where the '1' needs to be the current user's id. But when I change the where clause to:</p> <pre><code>-&gt;Where('c.user_id = ?', '$this-&gt;getUser()-&gt;getGuardUser()-&gt;getId()') </code></pre> <p>I get no results.</p> <p>Any ideas?</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