Shaun and I were discussing some issues with duplicate Property Set names and I thought I’d bring it up here to broaden the discussion.
I discovered it when I couldn’t find a way in a snippet to get a named property set associated with an element (perhaps a separate issue) short of a brute-force iteration through the attached sets looking for the name. (There may be an easier way using getOne() but I haven’t found anything that works).
I originally got the set with:
$modx->getObject('modPropertySet',array('name'=>'SetName'));
I realized, though, that this won’t work if more than one set has the same name. I think we’ve been assuming that many elements would have a Property Set called "default" so there’s a problem. It gets worse when you consider that in Tools | Property Sets, you can divorce a set from all elements, potentially leaving you with a bunch of sets called "default" and no way to tell them apart without looking at the properties themselves.
We can’t prefix the element names to them because they can be attached to more than one element.
As an alternative, we could require unique names for property sets, but then what happens if two add-ons each try to add a "default" property set during the package install? They could be renamed to default1, default2, etc., but that creates its own problems (like what happens on reinstall and update, for example).
I think that the element_property_sets table solves the duplicate name problem somewhat, so maybe we just encourage people to use a prefix (or suffix) with their property sets, allow duplicates names, and hope things don’t get out of hand.
That would mean that $getObject() couldn’t be counted on to find them, so we’d probably want to make sure that
$element->getOne('modPropertySet',array('name'=>'setName'));
would retrieve a named set (it doesn’t appear to now).
I hope this makes sense and I’m not missing something obvious.