<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Doing a join doesn't return the query interface, but rather the
alias that was assigned to the joined table. Since variable
assignment is processed left to right once it processes the ::join
method your $users variable now contains the table alias.<br>
<br>
What you want to do is stop your chaining before any methods that
don't return the SelectQuery object you are building:<br>
<br>
$query = db_select('user_badges_user', 'ubu')<br>
->fields('u', array('uid', 'name'))<br>
->condition('ubu.bid', $badge->bid); // Up to here you
get a SelectQueryInterface returned and assigned to query<br>
$query->join('users', 'u', 'u.uid = ubu.uid'); // Calls the join
method on $query, but doesn't assign the return;<br>
$users = $query->execute(); // Returns the
DatabaseStatementInterface that you pull your results from<br>
<br>
Generally I try to add joins at the beginning of the construction.
It seems to make it easier to read (it seems most of Drupal's core
code does the same), so I would write this query like this:<br>
<br>
$query = db_select('user_badges_user', 'ubu');<br>
$query->join('users', 'u', 'u.uid = ubu.uid');<br>
$query->fields('u', array('uid', 'name'))<br>
->condition('ubu.bid', $badge->bid);<br>
$users = $query->execute();<br>
<br>
You could assign $users when you add the fields and conditions, but
this does make it easier if you want to add anything else to the
query down the road. <br>
<br>
Easiest thing to remember is that if you get a non-member/non-object
error, then the item right above that doesn't return the proper
class and you should stop variable assignment there and instead just
call the method without assignment (ie: $query->join('users',
'u', 'u.uid = ubu.uid')). <br>
<br>
Chaining might look a little better and save a few keystrokes, but
it really doesn't bring any performance enhancements and can keep
headaches to a minimum, especially when working on classes you
aren't that familiar with. <br>
<br>
<br>
<pre class="moz-signature" cols="72">Jamie Holly
<a class="moz-txt-link-freetext" href="http://www.intoxination.net">http://www.intoxination.net</a>
<a class="moz-txt-link-freetext" href="http://www.hollyit.net">http://www.hollyit.net</a></pre>
<br>
On 10/25/2011 1:48 PM, Ms. Nancy Wichmann wrote:
<blockquote
cite="mid:1319564925.28862.YahooMailNeo@web180315.mail.gq1.yahoo.com"
type="cite">
<div style="color:#000; background-color:#fff; font-family:arial,
helvetica, sans-serif;font-size:12pt">
<div><span>Using the Boombatower conversion tool, my query comes
out to:</span></div>
<div><span> $users = db_select('user_badges_user', 'ubu')<br>
->fields('u', array('uid', 'name'))<br>
->condition('ubu.bid', $badge->bid)<br>
->join('users', 'u', 'u.uid = ubu.uid')<br>
->execute();<br>
</span></div>
<div><br>
<span></span></div>
<div><span>But when I run this, I get:</span></div>
<div><b>Fatal error</b>: Call to a member function execute() on
a non-object</div>
<div><br>
</div>
<div>Joins are getting to be a major pain in the derriere.</div>
<div><br>
</div>
<div>Trying this also fails with the same message:</div>
<div><span> $users = db_select('user_badges_user', 'ubu')<br>
->fields('u', array('uid', 'name'))<br>
->condition('ubu.bid', $badge->bid)<br>
->join('users', 'u', 'u.uid = ubu.uid');<br>
$users->execute();<br>
</span></div>
<div><br>
</div>
<div>------------------------------------------------------------------------------------------------------------<br>
</div>
<div>And does anyone know why I so rarely get answers to my
questions on this list?<br>
</div>
<div> </div>
<div><font color="#ff007f" face="bookman old style, new york,
times, serif" size="4"><i><strong>Nancy</strong></i></font></div>
<div><font face="arial, helvetica, sans-serif">Injustice
anywhere is a threat to justice everywhere. -- Dr. Martin L.
King, Jr.</font></div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
</body>
</html>