Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » ListboxField for Many_Many - Roadmap help needed!

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 277 Views
  • MartinPhone
    Avatar
    Community Member
    51 Posts

    ListboxField for Many_Many - Roadmap help needed! Link to this post

    I've made a few sites with SS - I'm by no means an expert and I make sites just for friends and family, but I'm familiar with extending a site etc. I'm just needing a little help seeing the bigger picture. Just getting a bit confused at the moment.

    The site in question, if you're interested is this - http://thelittleescape.com The site has been live for about a year and the way in which it has been used suggests a little restructuring.

    It's a clinic where one Practitioner may offer various Treatments and each Treatment can be offered by more than one Practitioner.

    I want to link to the many Treatments offered by each Practitioner on their pages, and the many Practitioners who offer each Treatment on those pages. (The aim is to remove the page listing the billions of Practitioners as it's a bit pointless and there's too much duplication of content).

    Now this is where it gets fuzzy.

    I'm not quite sure if I need distinct Treatment and Practitioner objects if I've already got TreatmentPage and PractitionerPage as I can surely put all the extra data/functions/whathaveyou in there? If I have separate objects - I'm looking and many_many and belongs_many_many - can pages be many_many? Does that even make sense? I guess each Treatment object will have a $has_one for the TreatmentPage... but that seems a bit pointless... as I said. Fuzzy.

    It seems most sensible to have a ListboxField or checkboxsetField on the Practitioner CMS page populated by querying the DB for all the Treatments but (and this seems to be my stumbling block) I can't populate the ListboxField despite many attempts, following where other forum posts have gone before.

    My aim - we set the Treatments offered within each Practitioner page in the CMS, and everything works both ways (see Treatments from Practitioners' pages and vice versa).

    Ultimately, I'm just not sure I'm even going about this in the right way and any advice would be appreciated! Very sorry if any of this is too vague, or too specific.

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: ListboxField for Many_Many - Roadmap help needed! Link to this post

    Sounds right, Practitioner will have many_many Treatments & Teatments belong_many_many Parctitioner.
    Pages can have a relationship with other pages this way, or with has_one or has_many

    PractitionerPage extends Page {
    $many_many = array('teatments' = > 'TreatmentPage');
    }

    TreatmentPage extends Page {
    $belongs_many_many = array('practitioners' = > 'PractitionerPage');
    }

    So on the treatment page you can use
    <% control practitioners %>

    And on the practitioners page
    <% control teatments %>

    Have a go, if you get stuck, come back and post code examples thats what I do.

  • MartinPhone
    Avatar
    Community Member
    51 Posts

    Re: ListboxField for Many_Many - Roadmap help needed! Link to this post

    Thanks a lot for this. much much appreciated. I will give it a shot.

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