Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Filtered dataobject by Parent

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

Page: 1
Go to End
Author Topic: 359 Views
  • Craftnet
    Avatar
    Community Member
    58 Posts

    Filtered dataobject by Parent Link to this post

    Hi, I have
    DataObject that is assigned to TownPage
    I have a few TownPage Page on site.

    Using this function i filtered dataobject by Status and Waznosc

    function ListObiektsPaid() {
    $now = date('Y-m-d H:i:s');
    $where = "Created <= '$now' AND Waznosc > '$now'";

    return Dataobject::get('Obiekt', "Status='Oplacony' AND $where", 'Created DESC');
    }


    but in all townPage dataobject is show - I would also filtered by Parent ID.

    The idea is that if DataObject is assigned to a specific town Page i want to just be there show

    To TownPage are assigned DataObject by checkbox (tutorial from ssbits - dataobjects-as-pages-part-2)

    Sorry for my bad English

  • martimiz
    Avatar
    Forum Moderator
    1086 Posts

    Re: Filtered dataobject by Parent Link to this post

    Hi,

    If your ListObiectsPaid() function is part of your TownPage, you can either add this to your query: " AND TownPage_ID = ' $this->ID'" or filter the relation object directly. Example again on SSBits:

    http://www.ssbits.com/snippets/2010/getting-items-from-a-has-many-or-many-many-relation/

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