Query a Template or TV Based on its Properties?

Is it possible via xPDO methods to find elements by their property set values? I know the properties are stored as a json object, thus my initial assumption would be that this can not be done in a straightforward manner … but wanted to check anyway.

My concept involves setting a property on certain TVs to identify their data type (for example, data-type = physical-address for those TVs that make up a full address) and to use as a way of later performing certain operations without necessarily knowing the TV names or how many TVs there are of a certain type.

It’s not straightforward as such. You’ll effectively need to design a database query to do what you need and then you can put that through an xPDO query.

https://docs.modx.com/xpdo/2.x/class-reference/xpdoquery

That’s the starting point - the structures of what you need to join to what should be a matter of creating what want and then working your way through the database structure connections to join those dots.

We can possibly help further on what joins to what with a few more details/a pratical example.

I appreciate the feedback. I can design the query … just wanted to make sure I wasn’t going to be reinventing the wheel by doing so!

I don’t know how extensively modxers incorporate the properties of elements into their coding, but I wonder if it the core developers might consider moving the properties out into a separate table rather than encapsulating them in json within an element’s record.

Not as far as I’m aware. My understanding is that property sets are one of the more undervalued/underappreciated features in MODX.

I’ve been using Revo since it was released and I don’t have them in use anywhere because I’ve not yet integrated them into my mental workflow.

Because not many people are using them, not much has been done by way of extras (that I’m aware of). A quick web search for ‘modx extras property sets’ turned up precious little, but might be worth a quick look if you haven’t already in case it leads you to some helpful material on interacting with them programatically.

I use properties fairly often, but not for TVs.

In fact I don’t use TVs for anything that involves searching or sorting. TVs are kind of a bastard child in MODX. They’re values are resource-specific, and they are meant to either hold the content of extra resource fields or control the presentation of specific resources.

They are problematic for storing data, though (as are properties). The “data” stored in TV’s is not all in one table because TVs set to their default value have no record in the table holding the modTemplateVarResource objects.

That said, I think your idea could make sense in certain use cases, though it’s difficult to say without knowing more.