redis-om-python
redis-om-python copied to clipboard
Missing support for List of EmbeddedJsonModel
We miss the support of defining a JsonModel with a field that is defined as a List of EmbeddedJsonModel . It is highly required to support our DB modeling to enable RedisSearch with a single index on a JsonModel and all its EmbeddedJsonModel fields, whether they are a single field or a List.
@oren-twigo Can you give me a base example of how you're looking to use it. Is the idea that this would be extensible (i.e a List contains a List, contains a List...), are you looking for a single level of depth?
I'd actually love to see the combination of your model and Search query if you're willing! For my own curiosity, I'd like to know if you're using async or sync - but it's less important.
Thanks again!
@chayim I am looking for two levels of depth, but it is a fixed and strict depth, not dynamic depth. find below my code example.
We collect data about users from external platforms. so the main model is "ExternalUsersData". each user contains data from one or more platforms. so we have a list of "UserPlatformData". each user platform data can contain data of one or more social media platforms this user is linked to - "SocialMediaProfile". so we have 3 levels of depth: ExternalUsersData -> (1:N) -> UserPlatformData -> (1:N) -> SocialMediaProfile
I did not get to the point of doing the search queries, so neither "async" or "sync" (yet) :)
I hope it helps.
`class SocialMediaProfile(BaseEmbeddedJsonModel): social_media_name: SocialMediaNameField = Field(index=True) profile_id: str = Field(min_length=1,max_length=100,index=True)
class UserPlatformData(MyBaseModel): # <- Should be BaseEmbeddedJsonModel when Python OM will support list of EmbeddedJsonModel platform_id: int = PlatformField(index=True) external_platform_user_id: str = Field(min_length=1,max_length=100,index=True) user_name: str = EnglishOnlyTextField(index=True, full_text_search=True) display_name: str = UnicodeTextField(min_length=1, max_length=250, index=True, full_text_search=True) description: str = UnicodeTextField(min_length=0, max_length=500, index=True, full_text_search=True) location: Optional[Location] social_media_profiles: List[SocialMediaProfile] profile_media_file: MediaFile cover_media_file: MediaFile email: Optional[EmailStr] = Field(index=True) phone_number: Optional[str] = PhoneNumberField(index=True) website_url: Optional[AnyHttpUrl] = Field(index=True) joined_platform_date_utc: date created_timestamp_utc: datetime updated_timestamp_utc: datetime
class ExternalUsersData(BaseJsonModel): class Meta: model_key_prefix = "external-users-data" index_name = "external-users-data.index"
@property
def external_user_uuid(self):
return self.pk
external_user_platform_data: List[UserPlatformData]
created_timestamp_utc: datetime
updated_timestamp_utc: datetime
`
@simonprickett I believe this has been added?
@simonprickett I believe this has been added?
Not at multiple depth levels IIRC.