[support] Converting a query to D7

Vaibhav Jain in.vaibhavjain at gmail.com
Thu Oct 13 06:48:57 UTC 2011


Hey Michael,

$query = condition('ubr.rid', '@todo Set the appropriate argument.')
Definitely my bad over here.

should have been
$query->condition('ubr.rid', '@todo Set the appropriate argument.')

On Wed, Oct 12, 2011 at 1:06 PM, Michael Prasuhn <mike at mikeyp.net> wrote:

> Dipen wrote:
> > http://upgrade.boombatower.com/tools/sql/inline
> >
> > db_select('user_badges_roles', 'ubr')
> >   ->fields('ubr', array('rid', 'ubb'))
> >   ->join('user_badges_badges', 'ubb', 'ubb.bid = ubr.bid')
> >   ->condition('ubr.rid', '@todo Set the appropriate argument.')
> >   ->execute();
>
> 1. the fields section is plainly incorrect as it won't select any fields
> from user_badges_badges and has an erroneous field from user_badges_roles
>
> 2. Join just returns the tables alias, not a select query object, so
> it's not chainable.
>
> Vaibhav Jain wrote:
> > You can use this query like this
> > $query = db_select('user_badges_roles', 'ubr')
> >   ->fields('ubr', array('rid', 'ubb'))
> >   ->join('user_badges_badges', 'ubb', 'ubb.bid = ubr.bid');
> >
> > $query = condition('ubr.rid', '@todo Set the appropriate argument.')
> >   ->execute();
>
> Same problem as number 1 above, and what on earth is the condition
> function? I know of no procedural function in Drupal by that name.
>
>
> Nancy, here's what you want:
>
> $query = db_select('user_badges_roles', 'ubr');
> $query->innerJoin('{user_badges_badges', 'ubb', 'ubb.bid = ubr.bid');
> $result = $query->fields('ubr', 'rid')
>  ->fields('ubb')
>  ->condition('ubr.rid' $YOUR_ARGUMENT)
>  ->execute();
>
> There may be a more elegant way to get structure the query, but this
> will get you the results you're looking for.
>
> -Mike
>
> __________________
> Michael Prasuhn
> mike at mikeyp.net
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>



-- 
Regards,
Vaibhav Jain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20111013/a6009851/attachment.html 


More information about the support mailing list