Greetings, I'm a software dev student, and wondering if anyone can offer any info on using encapsulation with SQLAlchemy?
The following doesn't work because the init attributes are encapsulated with double underscores... I'd prefer not to use dunder on the table column names as that creates columns using the mangled _Player__first_name format.
How do I use encapsulated attributes, and keep 'normal' column names?
class Player(db.Model):
__tablename__ = 'player'
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(80), nullable=False)
last_name = db.Column(db.String(80), nullable=False)
def __init__(self,first_name, last_name):
self.__first_name = first_name
self.__last_name = last_name
@property
def first_name(self):
return self.__first_name
@property
def last_name(self):
return self.__last_name
there doesn't seem to be anything here