Skip to content

Find nested model objects by _id (works with name, but not the id) #914

Closed Answered by hgalytoby
diegocgaona asked this question in Question
Discussion options

You must be logged in to vote

I've tested this query with no problems.

print(await Drinks.find({"drinks_tags._id": PydanticObjectId('661df66e53b0ca2825058801')}).to_list()) print(await Drinks.find({"drinks_tags._id": (await Drinks.find_one()).drinks_tags[0].id}).to_list())

output

[
Drinks(
  id=ObjectId('661df66e53b0ca2825058802'), 
  revision_id=None, 
  name='123',
  drinks_tags=[
    DrinksTags(
      id=ObjectId('661df66e53b0ca2825058801'), 
      revision_id=None, 
      name='123',
      color=None
    )
  ]
)
]

[
Drinks(
  id=ObjectId('661df66e53b0ca2825058802'), 
  revision_id=None, 
  name='123',
  drinks_tags=[
    DrinksTags(
      id=ObjectId('661df66e53b0ca2825058801'), 
      revision_id=None, 
      na…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by diegocgaona
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants