5542 Posts in 1739 Topics by 1225 members
|Go to End|
8 January 2009 at 4:05pm Last edited: 8 January 2009 4:07pm
OK, this might be an interesting one, perhaps I'm not seeing it because I over-think it. Just suppose I have a product page class, Product.php and its template Product.ss. For simplicity's sake, let's assume the product displayed has two properties, a color and a availability status. So to set up the structure to manage colors per product page, I create a dataobject called color, set up a many_many relationship, display it in a separate tab in the CMS, you know, the works. I can now "attach" colors to each product page, and have it iterated over in the template by using a control block. I can do the same for the availability status. But what if the availability status is color dependent? So, for instance, in a particular product page I have three colors set up (red, green, and blue), but only two of them are available? In other words, how can I relate the "color many_many" to the "availability many_many"? So to speak, I envision a ManyManyComplexTableField of some sorts to handle two many_many relations, as if it would have two independent columns of checkboxes, if you catch my drift. Is there a way to do this?
Thanks for thinking with me on this one, maybe I overlook the obvious...
9 January 2009 at 8:35am
Your data model won't support the kind of structure you're looking for.
You'll probably want to create a ProductType record, which records one colour-availability pair:
* Product has_many ProductType
* ProductType has_one Product
* ProductType has_one Color
* ProductType has_one Availability
You can then create a TableField, listing all of the ProductTypes linked to a Product, that has a dropdown field for Color and Availability.
9 January 2009 at 2:18pm
Thanks for your suggestion! But: doesn't this limit me to one color-availability pair per Product page? In other words, because it is a has_many situation, if I select for instance "blue-available" in one Product page, I can not select that one anymore in another Product page?
9 January 2009 at 5:34pm
No, a has_one relationship with one obejct doesn't exclude another object having an has_one object with the object.
Hopefully that made sense.
9 January 2009 at 7:36pm Last edited: 12 January 2009 9:08pm
Edited: Removed code, I put wrong code here, see later post.
10 January 2009 at 2:24am Last edited: 12 January 2009 9:16pm
Hmm, wait, perhaps I misunderstood: did you actually mean that every row in the tablefield will contain a dropdown? That would actually help me, I think...
Edit: that's not what you meant indeed and also what -of course- would not be the solution
12 January 2009 at 9:15pm Last edited: 12 January 2009 9:18pm
OK, so I think I misunderstood Sam's post (sorry Sam), but I thought of another (perhaps temporary) solution. Because there's a limited amount of colors to choose from, I just made one Color dataobject, with an extra boolean "Status" field. I then just batch upload a double list of colors in the corresponding database table, half of which have the status field set to 1 and the other half to 0, so the CMS-user can choose between an available-color and the-same-but-not-available-color. No biggie. I think my original post was not so clear perhaps.
Still, also in this case I'm kind of suffering from the problem I posted here (code posted does not reflect the above new situation yet, but same results nevertheless):
|Go to Top|