Skip to content

Add support for deferred NavigationProperty handling in manual models #3

Open

Description

@tuomur

Currently NavigationProperty objects need to refer to an Entity class. Two classes referencing eachother does not work unless NavigationProperties are added after everything else. Should we support Entity refs as strings? How to get the Entity behind the string?

Activity

  1. tpow commented on Jan 22, 2019

    @tpow

    It would be really helpful to be able to pass the Entity refs as strings.

    In the meantime, a workaround might be to specify the NavigationProperties in the __new__ method. This makes for somewhat ugly code, but it solves the problem when entities or types aren't declared in advance (possibly due to referencing each other), but will be available when the class is instantiated.

    For example:

    class ProductPart(Service.Entity):                                               
        __odata_type__ = 'ODataTest.Objects.ProductPart'                             
        __odata_collection__ = 'ProductParts'                                        
        id = IntegerProperty('PartID', primary_key=True)                             
        name = StringProperty('PartName')                                            
        size = DecimalProperty('Size')                                               
        product_id = IntegerProperty('ProductID')                                    
                                                     
        def __new__(cls, *args, **kwargs):
             cls.product = NavigationProperty('Product', ProductWithNavigation,
                       foreign_key=ProductPart.product_id)
             return super(ProductPart, cls).__new__(cls, *args, **kwargs) 
             # in Python 3 code, super(ProductPart, cls) can be simplified to super()```
  2. added a commit that references this issue on Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions