Jump to:

3372 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3 datamodel relation filters

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

Page: 1
Go to End
Author Topic: 1344 Views
  • spierala
    Avatar
    Community Member
    80 Posts

    SS3 datamodel relation filters Link to this post

    Hello all,
    I just try to figure out the SS3 Relation filters as described here:
    http://doc.silverstripe.org/framework/en/topics/datamodel

    There is one example which does not seem to work:

    $members = Member::get()->filter(array(
    'Groups.Title:StartsWith' => array('A', 'B'),
    ));

    It should return all members in groups whose names start with 'A' or 'B'... but it does not.

    For sure in my database is a group with title starting with 'A': Administratoren

    Has anyone already experience with that?
    Kind regards,
    Florian

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: SS3 datamodel relation filters Link to this post

    similar problem here.

    given 2 classes:
    Card many_many Tags
    Tag belongs_many_many Cards

    both classes have a Title field; there are multiple Card objects linked to a tag with Title 'test'

    some 'relation filters' i tried (none of them working):

    $cards = Card::get()->filter(array(
    'Tags.Title' => 'test'
    )); //throws an error

    $cards = Card::get()->filter(array(
    'Tags.Title' => array('test')
    )); //throws an error

    $cards = Card::get()->filter(array(
    'Tags.Title:StartsWith' => array('test')
    )); //no results returned

    the only filter i got to work is the following:

    $cards = Card::get()->filter(array(
    'Tags.Title:ExactMatch' => 'test'
    ));

    looks like this thing is rather buggy?

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: SS3 datamodel relation filters Link to this post

    Hello guys,

    I was also trying to use this relation filtering. Then I found this post, I have tried like schellmax and nothing. I guess I am doing something wrong with the names. Because is the same structure as its describe here.

    Dataobject dLab

    static $many_many = array(

    'Persons' => 'dPerson'

    );

    Dataobject dPerson

    static $belongs_many_many= array(

    'Labs' => 'dLab'

    );

    Relation table is name "dLab_Persons"

    Then I use:

    $children = dLab::get()->filter(array(

       'dPerson.firstname:ExactMatch' => 'Matthias'

    ));

    Do you see something wrong??

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: SS3 datamodel relation filters Link to this post

    @Bolixe: in your case it should be

    <pre>
    $children = dLab::get()->filter(array(
    'Persons.firstname:ExactMatch' =>'Matthias'
    ));
    </pre>

    note it's 'Persons.firstname', not 'dPerson.firstname'

    but no info yet about the other filters...

  • Baukez
    Avatar
    Community Member
    4 Posts

    Re: SS3 datamodel relation filters Link to this post

    One easy way to find out if the query works, it to append ?showqueries=1 to your URL, and see if the filters are applies at all.

    Anyway, I believe this feature is only working rather recently...

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: SS3 datamodel relation filters Link to this post

    Yeah, I tried with this code schellmax. But I think could be because of the classes I have.

    dLab and dPersons which are related, extends to MyDataObject which I created it, and then this one extend to DataObject from the core.

    So do you think could be because this MyDataObject class should be include in the filter of the query?? It came to my mind tonight in dreams hehehe.

    Thanks for the answer

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: SS3 datamodel relation filters Link to this post

    it's just been confirmed by 'UncleCheese' that relation filters aren't implemented yet. i'll post a comment in the docs

    see: https://groups.google.com/d/topic/silverstripe-dev/XF2OoYrwEWo/discussion

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: SS3 datamodel relation filters Link to this post

    Ok I have read the post yesterday. And since I only want to filter one relation I want to do by my raw sql.

    I have tried SQLQuery() and buildSQL() to put this in the DataObject. But all of them are deprecated.

    Did you try to use it??

    1344 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.