HamedMasafi / Nut

Advanced, Powerful and easy to use ORM for Qt
GNU Lesser General Public License v3.0
294 stars 75 forks source link

Cannot remove from database #31

Closed LinArcX closed 5 years ago

LinArcX commented 6 years ago

Hi. i have a favorites table(for a music app) and i want to remove some items from it. i wrote this method:

virtual void removeFromFavorites(QString title, QString path) override
    {
        Query<Favorites>* q = db.favorites()->query()->setWhere(Favorites::titleField() == title && Favorites::pathField() == path);

        q->toList();

        Favorites* fav = q->first();
        db.favorites()->remove(fav);
        db.saveChanges();
    }

but q is null. and subsequently the application crashes. although in db, i have a record like this: Marshall-Bruce Mathers. III | /home/linarcx/Music/06.justlikeit.mp3 why?

HamedMasafi commented 6 years ago

The q should not be null. Query::setWhere returns this so q will be query itself. https://github.com/HamedMasafi/Nut/blob/master/src/query.h#L452

Can you please send database and table class for testing?

LinArcX commented 6 years ago

Oh, q is filling:) I used where instead of setWhere and remove first condition and everything work! Is there any restrictions to pass 2 Qstrings in where Phrase?

HamedMasafi commented 6 years ago

No. there is not any restrictions. But your terms may not return a result. Check your data if there is a record with the given terms.