def test_create_item_mm_field(self):
        """
        REST Api: Test create with M-M field
        """
        client = self.app.test_client()
        token = self.login(client, USERNAME_ADMIN, PASSWORD_ADMIN)

        with model_mm_parent_data(self.appbuilder.session, 1, 4) as models:
            children_ids = [child.id for child in models[0].children]
            item = dict(field_string="new1", children=children_ids[0:2])
            uri = "api/v1/modelmmapi/"
            rv = self.auth_client_post(client, token, uri, item)
            self.assertEqual(rv.status_code, 201)
            data = json.loads(rv.data.decode("utf-8"))
            self.assertEqual(
                data[API_RESULT_RES_KEY],
                {"children": children_ids[0:2], "field_string": "new1"},
            )
            # Test without M-M field data, default is not required
            item = dict(field_string="new2")
            uri = "api/v1/modelmmapi/"
            rv = self.auth_client_post(client, token, uri, item)
            self.assertEqual(rv.status_code, 201)
            data = json.loads(rv.data.decode("utf-8"))
            self.assertEqual(
                data[API_RESULT_RES_KEY], {"children": [], "field_string": "new2"}
            )
            # Test without M-M field data, default is required
            item = dict(field_string="new1")
            uri = "api/v1/modelmmrequiredapi/"
            rv = self.auth_client_post(client, token, uri, item)
            self.assertEqual(rv.status_code, 422)
            data = json.loads(rv.data.decode("utf-8"))
            self.assertEqual(
                data, {"message": {"children": ["Missing data for required field."]}}
            )

            # Rollback data changes
            model1 = (
                self.appbuilder.get_session.query(ModelMMParent)
                .filter_by(field_string="new1")
                .one_or_none()
            )
            model2 = (
                self.appbuilder.get_session.query(ModelMMParent)
                .filter_by(field_string="new2")
                .one_or_none()
            )
            self.appbuilder.get_session.delete(model1)
            self.appbuilder.get_session.delete(model2)
            self.appbuilder.get_session.commit()

        REST Api: Test create with M-M field
        
tests/test_api.py