Rock U - Lava - Entity Commands

Transcribed Video Content

Okay. So let's look at the entity command within Lava. The entity command is super powerful because it allows you to get the data that you need right into your Lava template. Now, a lot of times, your Lava is past certain data, objects and and and variables. But it's not always the case that you're gonna have the data that you want, when you're getting to do some of the templates that you're going to build. Your what you're deciding with and what your plans are maybe wasn't thought of ahead of time by the developer and they didn't provide you with all the the data. These entity commands allow you to get whatever you want. So you can basically get anything within Rock, any different entity type, within Rock. You can go get the data you want and present it. So let's take a look at how they work. So they're a lot , some of the other blocks that we've seen, lava blocks. So they have an an end tag and an and a a start tag and an end tag. So in this case, the start tag is always gonna be the entity that you're trying to query on. So it's gonna be person in this case because I wanna get people and then I have in person for the close tag. And then within that those tags I can put any kind of logic that I want. But how do I know what people to get back? That's where you use these optional parameters. So in this case, we're gonna say where last name is equal to Decker. Okay. And that's gonna give me all the people in the database whose last name ends with Decker. I'm just gonna spin through them with this little for statement. I'm gonna print out their full name and there you go. So it's a very basic example of an entity command. Let's keep drilling a little bit deeper. So in this case, we're gonna keep extending off of the the previous example. So we're gonna keep the last name equals Decker. But now we're gonna say or and that's what these two bars mean or and then an and would be two ampersands. Okay. So that's the syntax within here of how you do an and or an or. So when you say or the position contains the word pastor. Okay. And that's what this symbol here is telling us and we'll go through what all those mean a little bit later. So we're basically saying where the last name is equal to Decker or the position contains the word pastor and then we're just gonna iterate through that same way as we did before. The only thing we did is we're just adding the the option of this displaying the position name. Now what we're doing up here too that you should you should be aware of is that we're querying on a property last name and position is actually an attribute. So this is actually showing you, you can query on either one of those, a property or an attribute all in the same syntax which is really powerful. And then the outputted results are down below. So , Tad shows up because his last name is is Decker and, know, his position has the word pastor. And Cindy, Noah and Alex are there because their last name is Decker. And then Pete Foster, his last name is not Decker but his position does have the word pastor in it. So that's a a good example of how you can do some very powerful querying based on properties and attributes. And these are the conditionals that you can use within your where clause. So we have the the ones that we've seen before equal, not equal, starts with greater than, less than, and those, but you also get other ones contains. We saw that one does not contain, ends with, is blank, is not blank, starts with. So some very powerful conditionals that you can use within your statements. Okay. So let's dig a little bit deeper. So in this case, in this example, we're not using the where clause. Instead, we're saying, hey, I want person whose ID is three. That's all I want. And that is Ted Decker in the database. Now if I wanted to get a couple different IDs and I knew them off off hand, I could say I want IDs three and four, which would give us Ted and Cindy. Another way you can do this is to use your data views. Hopefully, you've watched the data view video and you strategically created a set of data views that are reusable. And that reuse extends into Lava. So with this entity command, I can actually say, hey, give me all the people who match data view whose ID is one. Okay? Now that's super powerful. Another good reason to create a solid list of data views. But it may be the case that you want that data view but gosh, you just need to do a little bit more filtering and you don't wanna have to go in and and create another data view just for that use case. So you can extend that data view right inside of Lava and add additional where clause to it. So say, give me the the member adult members and attendees from the data view number one and then, what, just give me males in this case. And so that's what it will do. Now, simplifying this the the logic here that you still need all the other stuff but I'm just trying to simplify and only show you the top line. You can do a few more things, few more parameters you can pass through to your to your command. You can tell it to sort the data in a certain way. So in this case, we want to sort by last name and then after last name sort by first name. But when you sort by first name, do it in descending order. Okay. So this is just showing you all your different sort options. And that would give you those results. Now, can also choose to limit. So limit would give you just five results. So maybe you don't want all 10,000 records that might be retrieved by your your where clause. You just want five. You just say limit five and you get five. Another optional parameter is to say offset by five. So that says skip the first five and then give me the next five. And so this offset is really well used in paging. So if you wanna page through your results using these two optional parameters are really helpful. Okay. So we looked at how to do that with the group with the person entity. Just realize you can do it with entity any entity type within Rock. So here, we're just showing you the same exact thing with group and we're just kind of showing you groups whose group type ID is equal to 10 and we're sorting it by name and then we're just iterating over those groups. So just substitute group and group and group items with the entity that you want to query on and you'll have access to it. Now, sure to check out the Rocklava page for more information on entities. We go through a lot more examples of each of those, parameters and give you more tips and tricks.