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

17 views
Skip to first unread message

Vitaliy Tsymbalyuk

unread,
Jan 29, 2015, 3:56:57 AM1/29/15
to silverst...@googlegroups.com
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);

    }

    public function LitCategorys() {
        $CategorysList=$this->getManyManyComponents('LitCategorys')->sort('SortOrder');
        return $CategorysList;
    }

}
When I try link LitCategory to LinEntry, GridField show me LitCategorys from all site languages.
Problem in SQL query generated by $this->getManyManyComponents('LitCategorys')->sort('SortOrder'):
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 ... ?



Will Morgan

unread,
Jan 29, 2015, 10:30:32 AM1/29/15
to silverst...@googlegroups.com
Hi Vitaliy,

This group is for discussing core development of SilverStripe, not for giving help with people's sites.

Please kindly check out the IRC, forums, or StackOverflow's silverstripe tag if you still require help.

Cheers

On Thursday, January 29, 2015 at 8:56:57 AM UTC, Vitaliy Tsymbalyuk wrote:
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);

    }

    public function LitCategorys() {
        $CategorysList=$this->getManyManyComponents('LitCategorys')->sort('SortOrder');
        return $CategorysList;
    }

}
When I try link LitCategory to LinEntry, GridField show me LitCategorys from all site languages.
Problem in SQL query generated by $this->getManyManyComponents('LitCategorys')->sort('SortOrder'):
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`.
...
Reply all
Reply to author
Forward
0 new messages