Dot syntax in filter queries

56 views
Skip to first unread message

Olli Tyynelä

unread,
Dec 3, 2013, 9:35:55 AM12/3/13
to silverst...@googlegroups.com
I might be going daft here but just have to check this from the horses mouth :) and been doing magento work mostly for the past months so.

The dot syntax for filtering with has many relations seems to work:

NewsPage::get()->filter('NewsTags.ID', $tagIDs);

But there seems to be no reference of the functionaly in the documentation on this. Or I just cant seem to find it.

but noting anything "definitive" on the http://doc.silverstripe.org/framework/en/topics/datamode page..

Is that feature on the works still and thats not promoted as a possibility or am I just being blind on the doc pages?

:olli

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Dec 3, 2013, 3:07:04 PM12/3/13
to silverstripe-dev
Hi Olli

You have exposed another long standing "bug" in SS.... that the 404 pages often look broken ;-)  Formatting is gone as far as I can see.  There are no css files included in the page below except one for the tool bar. 


Inline images 1

As far as your question.  This Data Model page is key bit of documentation.  I wonder if it may be helpful to split this page into 

1. defining the datamodel
2. querying the datamodel

as right now it seems to talk a bit about both - making the page rather long - covering many topics.  BTW, should tags not be a many_many relation with NewsPage so that one tag can be used on several NewsPages? 

BTW, I believe you can also write:

$newsPageObject->NewsTags("ID", array(1,2,3));

But I am not sure!

Nicolaas



--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to silverstripe-d...@googlegroups.com.
To post to this group, send email to silverst...@googlegroups.com.
Visit this group at http://groups.google.com/group/silverstripe-dev.
For more options, visit https://groups.google.com/groups/opt_out.



--
Nicolaas Thiemen Francken  
Sunny Side Up Ltd  {
  Skype: atyourservicehour
  Phone: +64 4 889 2773 
  Emergencies: 0221697577
  n...@sunnysideup.co.nz
  http://www.sunnysideup.co.nz
}







image.png

Zauberfisch

unread,
Dec 3, 2013, 3:30:55 PM12/3/13
to silverst...@googlegroups.com
assuming Newstags is a hasmany or manymany, it would be:

$newsPageObject->NewsTags()->filter("ID", array(1,2,3));

On 03.12.2013, at 20:07, Nicolaas Thiemen Francken - Sunny Side Up <ma...@sunnysideup.co.nz> wrote:

Hi Olli

You have exposed another long standing "bug" in SS.... that the 404 pages often look broken ;-)  Formatting is gone as far as I can see.  There are no css files included in the page below except one for the tool bar. 


<image.png>

Olli Tyynelä

unread,
Dec 3, 2013, 4:59:47 PM12/3/13
to silverst...@googlegroups.com
Hi,

Yay I exposed a bug :D

As far as your question:

Well the underlying model on my case example was NewsPages hasMany newsTags and they belong to many pages.

The implementation of my line of code was that I had a sitetree extension to create a "loose relation" that sets up a comma separated field of ID:s of tags, so on those pages i dont have a $newsPageObject per ce.

Anyways the issue was that out the fastest way filter out the pages that would relate to tags defined on that Page e.g. "a list of related news". Choices were to create nested loops, or do a joins manually and then I remembered valugelly at some point the docs or something referred to the dot on filering relations.

But I just couldn't find a definite sample on the docs and in my opinion that I't ease up the pain on writing joins is quite good to have as an example there :).

Everything else is there but its missing something that you can google or ctrl-f with "filterin by relations" or "filter by has many" or similar.

Two simple samples should do it:

"get pages that have a tag that starts with the string" or using the player idea thats there.. get teams that have players with first name  or team(s)  (would of course be the one) with the player id or an id list to get many teams. :)


Actually.. need to go to bed but was looking at this:

$newsPageObject->NewsTags()->filter("ID", 
array(1,2,3));

Doesn't that filter tags 1,2,3 from the tags that have tagged FOR that page. On the case example i'm interested on NewsPages that are tagged with tags 1,2,3

Eg
NewsPage::get()->filter('NewsTags.ID',array(1,2,3));

or

Datalist::create("NewsPage")->filter('NewsTags.ID', array(1,2,3));

Cheers,
Olli






2013/12/3 Zauberfisch <ad...@zauberfisch.at>

c...@silverstripe.com

unread,
Dec 3, 2013, 5:52:35 PM12/3/13
to silverst...@googlegroups.com, n...@sunnysideup.co.nz, ma...@sunnysideup.co.nz
Nicolaas, 

Feel free to divide that page up as you suggest and submit a pull request. Have a look at how we split up sections in the git repo in the Testing section of the docs as an example: http://doc.silverstripe.org/framework/en/topics/testing/



Cam

Reply all
Reply to author
Forward
0 new messages