Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deferred NavigationProperty handling in manual models #3

Open
tuomur opened this issue Apr 14, 2015 · 1 comment
Open

Comments

@tuomur
Copy link
Owner

tuomur commented Apr 14, 2015

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?

@tpow
Copy link

tpow commented Jan 22, 2019

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()```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants