Working on a simple one-off project, and am trying to integrate the ORM library to get some experience with it. I ran into one issue, and had some questions:
- These imports in persistence didn’t work for me based on how the tutorial said to create the folder structure:
from app.server_lib.crud import security
from app.client_lib.crud.particles import
I had to change them to this:
from . import security
from .lib.crud.particles import ModelSearchResults
-
It doesn’t seem possible to use get to get a single item using something other than the uid. In my case I have a unique field in the table I want to fetch an item by. I could use search, check the length, and get the first element, but it’d be really nice if there were an equivalent to the Anvil data tables get. Maybe there’s something I’m just not seeing to do that?
-
Related to #2 above, how would I go about getting just the first item out of a set of search results? The ModelSearchIterator doesn’t respond well to next(results), claiming it’s not an iterator. What I ended up doing is very hacky:
rooms = Room.search(roomid=self.url_dict['id'])
for room in rooms:
self.roomname.text = room.name
break
-
Is there an order by equivalent for search?
-
How do you go about searching by linked table rows? I’d assumed it’d be by passing in the full object, but that gives me an invalid query value issue. It was for this model:
@model_type
class Roll:
room = Relationship(class_name="Room")
name = Attribute()
when = Attribute()
rolls = Attribute()
And this search:
results = Roll.search(room=room)