Giter VIP home page Giter VIP logo

Comments (4)

b-admike avatar b-admike commented on August 16, 2024 1

@zmarouf I have tried your scenario with upsertWithWhere and was able to successfully get the following:
Steps to reproduce:

  1. create a LB 2.x app with empty-server template
  2. create a mysql datasource using the generator prompt slc loopback:datasource
  3. use slc loopback:model to create myModel
  4. make create-mymodel.js which calls automigrate function on myModel
  5. start app and in explorer do a POST request to myModels with following value:
{   "myField": [     {"atr1": "value1",      "atr2": "value2"     }   ] }
  1. Check database
mysql> select * from myModel;
+----+-------------------------------------+
| id | myField                             |
+----+-------------------------------------+
|  1 | [{"atr1":"value1","atr2":"value2"}] |
+----+-------------------------------------+
1 row in set (0.00 sec)

  1. do a POST request to UpsertWithWhere endpoint and specify the following:
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"myField\": [
    {\"atr1\": \"value3\",
     \"atr2\": \"value4\"
    }
  ]
}" "http://localhost:3000/api/myModels/upsertWithWhere?where=%7B%20%20%20%22myField%22%3A%20%5B%20%20%20%20%20%7B%22atr1%22%3A%20%22value1%22%2C%20%20%20%20%20%20%22atr2%22%3A%20%22value2%22%20%20%20%20%20%7D%20%20%20%5D%20%7D"
  1. check database again
mysql> select * from myModel;
+----+-------------------------------------+
| id | myField                             |
+----+-------------------------------------+
|  1 | [{"atr1":"value3","atr2":"value4"}] |
+----+-------------------------------------+
1 row in set (0.01 sec)

I have created a sample repo which has the app that can verify the issue is fixed here

from loopback-connector-mysql.

zmarouf avatar zmarouf commented on August 16, 2024

Further tests show that it happens with the way I use upsert or updateAttributes. I changed my code to use the static updateAll and it works now.

I still don't understand why what I was doing is wrong though, so if anyone has an explanation for me, I'm all ears :)

from loopback-connector-mysql.

smehrbrodt avatar smehrbrodt commented on August 16, 2024

I think this is fixed with 634a0a9

from loopback-connector-mysql.

johannesjo avatar johannesjo commented on August 16, 2024

This happens to me also with the standard create method.

from loopback-connector-mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.