I have two models that are in a one to many relationship. Inquiry ||------o<- Specialneed
I want to be able to insert multiple records in Specialneed, by using the relationship constructed in Flask SQLalchemy.
I can insert 1 record in Specialneed, like this:
applicationParams={
'startdate': request.form['startdate'],
'enddate': request.form['enddate'],
'starttime': request.form['starttime'],
'endtime': request.form['endtime'],
'budget': request.form['budget'],
'specialneed': [SpecialNeed(description=request.form['specialNeeds'])]}
But when I try to give 'specialneed'-parameter a list of the specialneeds entered in the form, it gives me the error:
(pymysql.err.InternalError) (1241, 'Operand should contain 1 column(s)')
[SQL: 'INSERT INTO specialneed (description, iid) VALUES
(%(description)s, %(iid)s)'] [parameters:
{'description': ['Speaks English', 'Can sing'], 'iid': 11}]
When I give it a list it looks like this in my code:
applicationParams={
'startdate': request.form['startdate'],
'enddate': request.form['enddate'],
'starttime': request.form['starttime'],
'endtime': request.form['endtime'],
'budget': request.form['budget'],
'specialneed': [SpecialNeed(description=[sn.strip() for sn in request.form['specialNeeds'].split('.')])]}
The sql insert query should look like this to succeed:
SQL: 'INSERT INTO specialneed (description, iid) VALUES
(%(description)s, %(iid)s)'] [parameters:
{'description': 'Speaks English', 'iid': 11},
{'description': 'Can sing', 'iid': 11}]
How should I do to manage it?