D
D
Dmitry2019-05-02 01:24:04
Django
Dmitry, 2019-05-02 01:24:04

What does association_proxy mean in sql_alchemy model?

The whole question is in the title, code example:

school = Table('school', metadata,
    Column('id', UUIDType(), primary_key=True),
    Column('title', String(255)),
)


class School:
    def __init__(self, title):
        self.id = uuid.uuid3(uuid.NAMESPACE_DNS, title)
        self.title = title
mapper(School, school)


education = Table('education', metadata,
    Column('school_id', UUIDType(), ForeignKey('school.id'), primary_key=True),
    Column('profile_id', UUIDType(), ForeignKey('profile.id'), primary_key=True),
    Column('start', DateTime),
    Column('end', DateTime),
)


class Education:
    title = association_proxy('school', 'title')
    def __init__(self, school_id=None, profile_id=None, start=None, end=None, profile=None,
            school=None):
        self.school_id = school_id or (school and school.id)
        self.profile_id = profile_id or (profile and profile.id)
        self.profile = profile
        self.school = school
        self.start = start
        self.end = end
mapper(Education, education, properties={
    'profile' : relationship(
        Profile,
        backref=backref('education'),
    ),
    'school' : relationship(
        School,
        backref=backref('education'),
    ),
})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question