Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3 Left Join Missing argument


Go to End


3 Posts   1233 Views

Avatar
Harley

Community Member, 165 Posts

23 June 2015 at 9:24am

Ok so I have a data object related to some other data objects and I'm trying to build a reporting page for them. So far I've got the code below in my page controller to display a form where I will begin to select filtering options for the report.

However I am getting this error due to the left join:

[Warning] Missing argument 2 for SQLQuery::addLeftJoin()

I would seem that the raw2sql is outputting this when I've debugged:

\'AgeRangeData\', \'CallEvent.AgeRangeData ID=AgeRangeData.ID)\'

I'm assuming that the backslashes is what is causing the error

public function ReportingFilter(){

$DataObjectsList = $this->dbObject('DataObjects')->enumValues();

$fields = new FieldList(
    new DropdownField('DataObjects', 'Data Objects', $DataObjectsList)
);

$actions = new FieldList(
    new FormAction("FilterObjects", "Filter")
);

return new Form($this, "ReportingFilter", $fields, $actions);
}

public function FilterObjects($data, $form){

$data = $_REQUEST;
$query = new SQLQuery();

$object = $data['DataObjects'];
$leftJoin = Convert::raw2sql("'" . $object . "', 'CallEvent." . $object . " ID={$object}.ID)'");

$query->selectField("CallEvent.ID", "ID");
$query->setFrom('`CallEvent`');
$query->setOrderBy('CallEvent.Created DESC');
$query->addLeftJoin($leftJoin);

return $query;
}

Any help really appreciated

Cheers

Avatar
Pyromanik

Community Member, 419 Posts

23 June 2015 at 9:33pm

No, the output of raw2sql is fine. The warning means exactly what it says. You're only passing one argument to addLeftJoin, when it expects 2.

$query->addLeftJoin($leftJoin);

But: http://api.silverstripe.org/3.2/source-class-SQLConditionalExpression.html#130
It's not a function you just pass raw SQL into.
$query->addLeftJoin($object, '"CallEvent"."'.$object.'ID" = "'.$object.'"."ID"');

Also, never ever use backticks (`).

Avatar
Harley

Community Member, 165 Posts

25 June 2015 at 6:56am

Thank you! Worked like a charm!