Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3.1 $sqlQuery->addInnerJoin Issue

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 359 Views
  • SS_Learner
    Avatar
    Community Member
    18 Posts

    SS3.1 $sqlQuery->addInnerJoin Issue Link to this post

    Hi Friends

    I am making a query using sqlQuery in Silverstripe 3.1 . Now when i try to add an inner join using
    $sqlQuery->addInnerJoin('Member', 'testTable.OwnerID = Member.ID');

    the raw query i am getting with this is something like
    INNER JOIN "Member" ON testTable.OwnerID = Member.ID,
    which when executed in mysql gives syntax error,as there should be no double quotes in the table name,when i remove the quotes,it works.
    But how can i resolve this in my code?

    Thanks for any kind of help.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: SS3.1 $sqlQuery->addInnerJoin Issue Link to this post

    The generated SQL is correct. SilverStripe runs MySQL in ANSI mode, which means that database, table and column names should be enclosed in double quotes (“) rather than the normal back ticks (`). If you are running the query in a mysql shell, or through something like PHPMyAdmin, you need to run

    SET sql_mode=‘ANSI’;

    first.

    359 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.