Re: [sqlalchemy] Recommended way to delete record given instance?
Thanks for the suggestion, that seems to work perfectly! I'm not sure why the docs made deletions sound more complex than that. Of course, I may have just missed this. On 2/6/16, Thierry Floracwrote: > Hi ! > > Did you try "session.delete(myrecord)" ? > > Best regards, > Thierry > > > 2016-02-06 5:16 GMT+01:00 Alex Hall : > >> Hello all, >> Another basic question: given an instance of a record, can I somehow >> delete the record from a table? The longer story is this. >> >> I have my app, which lists tables on the left and the selected table's >> rows on the right. Adding and editing rows both now work correctly >> (though >> I have yet to do serious validation--thanks for all your thoughts on >> that, >> by the way). Now I just need to get deletion working. However, because >> the >> user could be looking at any table, I can't do >> table.query.filter(id==x).delete() >> because I can't know what field to use as the search field in that query. >> One table might have an ID field, another something different. I do, >> however, have the entire object representing the row selected for >> deletion. >> Could I somehow issue a delete statement using that whole object, and >> know >> that this will work for any table? I hope I'm making sense--it's been a >> long day. Thanks! >> >> >> -- >> Alex Hall >> Automatic Distributors, IT Department >> ah...@autodist.com >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sqlalchemy+unsubscr...@googlegroups.com. >> To post to this group, send email to sqlalchemy@googlegroups.com. >> Visit this group at https://groups.google.com/group/sqlalchemy. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > http://www.imagesdusport.com -- http://www.ztfy.org > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Recommended way to delete record given instance?
Hi ! Did you try "session.delete(myrecord)" ? Best regards, Thierry 2016-02-06 5:16 GMT+01:00 Alex Hall: > Hello all, > Another basic question: given an instance of a record, can I somehow > delete the record from a table? The longer story is this. > > I have my app, which lists tables on the left and the selected table's > rows on the right. Adding and editing rows both now work correctly (though > I have yet to do serious validation--thanks for all your thoughts on that, > by the way). Now I just need to get deletion working. However, because the > user could be looking at any table, I can't do > table.query.filter(id==x).delete() > because I can't know what field to use as the search field in that query. > One table might have an ID field, another something different. I do, > however, have the entire object representing the row selected for deletion. > Could I somehow issue a delete statement using that whole object, and know > that this will work for any table? I hope I'm making sense--it's been a > long day. Thanks! > > > -- > Alex Hall > Automatic Distributors, IT Department > ah...@autodist.com > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy+unsubscr...@googlegroups.com. > To post to this group, send email to sqlalchemy@googlegroups.com. > Visit this group at https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > -- http://www.imagesdusport.com -- http://www.ztfy.org -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Recommended way to delete record given instance?
Hello all, Another basic question: given an instance of a record, can I somehow delete the record from a table? The longer story is this. I have my app, which lists tables on the left and the selected table's rows on the right. Adding and editing rows both now work correctly (though I have yet to do serious validation--thanks for all your thoughts on that, by the way). Now I just need to get deletion working. However, because the user could be looking at any table, I can't do table.query.filter(id==x).delete() because I can't know what field to use as the search field in that query. One table might have an ID field, another something different. I do, however, have the entire object representing the row selected for deletion. Could I somehow issue a delete statement using that whole object, and know that this will work for any table? I hope I'm making sense--it's been a long day. Thanks! -- Alex Hall Automatic Distributors, IT Department ah...@autodist.com -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.