Guest User

Untitled

a guest
Jun 19th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. content_table = Table('content', metadata,
  2. Column('id', Integer, primary_key=True),
  3. Column('locale', String, nullable=False),
  4. Column('countryId', Integer),
  5. Column('cat', String),
  6. useexisting=True
  7. )
  8. class Content(object):
  9. def __init__(self, id=None, locale=None, countryId=None, cat=None, tag=None):
  10. self.id = id
  11. self.locale = locale
  12. self.countryId = countryId
  13. self.cat = cat
  14. self.tag = tag
  15. def __repr__(self):
  16. return "Content Id %i" % self.id
  17.  
  18. mapper(Content, content_table)
  19.  
  20. cat_table = Table('cat', metadata,
  21. Column('id', Integer, primary_key=True),
  22. Column('name', String(128), nullable=False),
  23. Column('tag', String(128), nullable=False),
  24. Column('ranking', Integer(2)),
  25. useexisting=True
  26. )
  27. cat_locale_table = Table('cat_locale', metadata,
  28. Column('id', Integer, ForeignKey('cat.id'), primary_key=True),
  29. Column('contentId', None, ForeignKey('content.id')),
  30. useexisting=True
  31. )
  32.  
  33. class Cat(object):
  34. def __init__(self, id=None, name=None, tag=None, ranking=None):
  35. self.id = id
  36. self.name = name
  37. self.tag = tag
  38. self.ranking = ranking
  39.  
  40.  
  41. mapper(Cat, cat_table, properties={
  42. "contents": relation(Content, lazy=False, secondary=cat_locale_table)
  43. })
  44.  
  45.  
  46. #### This line throws the following error:
  47.  
  48. sa.query(Cat).order_by(Cat.name).options([eagerload('contents')]).all()
  49.  
  50.  
  51. InvalidRequestError: Mapper 'Mapper|Cat|cat' has no property 'contents'
Add Comment
Please, Sign In to add comment