Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Querying multiple pages from ids in one db field

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1083 Views
  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Querying multiple pages from ids in one db field Link to this post

    hi everyone,
    I have a 2x2 mysql table called 'Market' that contains an 'ID' column that maps to a Market's 'ID' in the SiteTree, and a 'MarketProducts' column that maps to ProductPage 'ID's in the SiteTree. here is what the table would look like:

    ID | MarketProducts
    24 | 25,26,28,29
    27 | 25,29

    on each Market's Page (who's id is contained in the first column, 'ID'), i want to display a Title and link to the ProductPages that are contained in the MarketProducts column. I am currently writing the controller for the class file, but am having problems with the DataObject::get method. here is what i have so far:

       function Markets(){
          $MP = DataObject::get("ProductPage", "ID = $this->MarketProducts");
          return $MP;
       }

    the MarketProducts datatype is Varchar, and contains multiple IDs, comma separated. not sure if that is messing me up, but i know the syntax is wrong because the whole front end breaks on the Market pages.

    sorry if this is a little confusing. I would appreciate any help anyone is willing to offer.
    Thaks again,
    -Chris

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Querying multiple pages from ids in one db field Link to this post

    just curious if anyone has any ideas on this. I would really appreciate some suggestions.

    thanks,
    -Chris

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Querying multiple pages from ids in one db field Link to this post

    Hi Chris...

    So if I understand correctly , you need a one to many relationship between markets and products , right ?

    SS can do this for you out of the box ...

    Have a look at the following tutorial :

    http://doc.silverstripe.com/doku.php?id=tutorial:5-dataobject-relationship-management&s=has%20many

    Keep us posted on your progress !

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Querying multiple pages from ids in one db field Link to this post

    that was exactly what i needed. thank you very much for your help.
    -Chris

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