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.

All other Modules /

Discuss all other Modules here.

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

Translatable adds a filter to the locale in only one sub-queries


Go to End


3 Posts   1081 Views

Avatar
WebSpilka

Community Member, 89 Posts

30 January 2015 at 12:51am

Edited: 30/01/2015 6:52am

Hi
I have next code

class LitCategory extends Page {

	private static $many_many = array(
			'LitEntrys' => 'LitEntry'
		);

}

class LitEntry extends DataObject {

	private static $belongs_many_many = array(
		'LitCategorys' => 'LitCategory',
	);


	public function getCMSFields() {
		
		$gridFieldConfig = GridFieldConfig_RelationEditor::create();
		$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
		$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));

		$gridfield = new GridField("LitCategorys", "Blog Categorys", $this->LitCategorys(), $gridFieldConfig);
		$fields->addFieldToTab('Root.LitCategorys', $gridfield);

	}

}

When I try link LitCategory to LinEntry, for example I type in GridField "земн" (look at atache) silverstripe return to me list LitCategorys from all site languages .
Silverstripe generate next query:
SELECT DISTINCT `SiteTree_Live`.`ClassName`, `SiteTree_Live`.`Created`, `SiteTree_Live`.`LastEdited`, `SiteTree_Live`.`URLSegment`, `SiteTree_Live`.`Title`, `SiteTree_Live`.`MenuTitle`, `SiteTree_Live`.`Content`, `SiteTree_Live`.`MetaDescription`, `SiteTree_Live`.`ExtraMeta`, `SiteTree_Live`.`ShowInMenus`, `SiteTree_Live`.`ShowInSearch`, `SiteTree_Live`.`Sort`, `SiteTree_Live`.`HasBrokenFile`, `SiteTree_Live`.`HasBrokenLink`, `SiteTree_Live`.`ReportClass`, `SiteTree_Live`.`CanViewType`, `SiteTree_Live`.`CanEditType`, `SiteTree_Live`.`Locale`, `SiteTree_Live`.`Priority`, `SiteTree_Live`.`IsTitleHide`, `SiteTree_Live`.`Version`, `SiteTree_Live`.`ParentID`, `LitCategory_Live`.`ItemsPerPage`, `LitCategory_Live`.`Paginate`, `LitCategory_Live`.`Templ`, `SiteTree_Live`.`ID`, CASE WHEN `SiteTree_Live`.`ClassName` IS NOT NULL THEN `SiteTree_Live`.`ClassName` ELSE 'SiteTree' END AS `RecordClassName` FROM `SiteTree_Live` LEFT JOIN `LitCategory_Live` ON `LitCategory_Live`.`ID` = `SiteTree_Live`.`ID` 
	WHERE 
		(`SiteTree_Live`.`ID` 
			NOT IN (SELECT DISTINCT `SiteTree_Live`.`ID` FROM `SiteTree_Live` LEFT JOIN `LitCategory_Live` ON `LitCategory_Live`.`ID` = `SiteTree_Live`.`ID` INNER JOIN `LitCategory_LitEntrys` ON `LitCategory_LitEntrys`.`LitCategoryID` = `SiteTree_Live`.`ID` 
						WHERE
								(`LitCategory_LitEntrys`.`LitEntryID` = '479') 
							AND (`SiteTree_Live`.`ClassName` IN ('LitCategory')) 
							AND (`SiteTree_Live`.`Locale` = 'uk_UA')
					)
		) 
		
		AND ((`SiteTree_Live`.`Title` LIKE '%земн%') OR (`SiteTree_Live`.`Content` LIKE 'земн%')) 
		AND (`SiteTree_Live`.`ClassName` IN ('LitCategory')) 
// how to insert here the following filter:
//      	AND (`SiteTree_Live`.`Locale` = 'uk_UA')
ORDER BY `SiteTree_Live`.`Title` ASC LIMIT 20

Translatable add locale filter to inner query, but not add this (AND (`SiteTree_Live`.`Locale` = 'uk_UA')) to outer query.
How to add locale filter : AND (`SiteTree_Live`.`Locale` = 'uk_UA') befor ORDER ... ?

Attached Files
Avatar
Pyromanik

Community Member, 419 Posts

30 January 2015 at 4:04am

привіт WebSpilka :)

This query does not seem to be the one generated by your getter.

It is getting all LitCategory pages where they are NOT related to the LitEntry you are on.
This is also notable as the sort is not by what you have specified.

The subquery is fetching all related LitCategory ID's, which is combined with an ID NOT IN - this seems to be the exact opposite of what you're after.

I assume you've manually edited the query to test it, as SilverStripe does not use backticks when generating SQL, so can you please confirm if these issues are also because of your testing?

Avatar
WebSpilka

Community Member, 89 Posts

30 January 2015 at 6:55am

Edited: 30/01/2015 6:57am

I edit my question
This query generated by silverstripe GridField
($gridfield = new GridField("LitCategorys", "Blog Categorys", $this->LitCategorys(), $gridFieldConfig);)
when I try link new Category to LitEntry

Attached Files