-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return the number of affected rows when run Mapper remove method #86
Comments
What are your thoughts @tonicospinelli? |
it is interesting! I new from here, but will give my 5 cents 😄 now, Probably, @ricardofontanelli could you give a example? |
@tonicospinelli tks for your response. Well, I'm trying delete an single record in the database, but the $file1 = new \stdClass;
$file1->id = 1248; //This record doesn't exist in the database, it could be null, false or a string, for example
$file2 = new \stdClass;
$file2->id = 3; // Real record that exist in the database
$mapper['local']->invoice_file->remove( $file1 );
var_dump( $mapper['local']->flush() );// Result 1 is = NULL
$mapper['local']->invoice_file->remove( $file2 );
var_dump( $mapper['local']->flush() );//Result 2 is = NULL Supposing that I changed my code and after that the |
@ricardofontanelli I got your point of view! In your case, you will remove in a controlled environment and you know only remove method will be called in you application. If you take a look inside of flushSingle method, it will call the methods Honestly, I don't think $db = new \Respect\Relational\Db(new PDO('connection', 'user', 'pass'));
$mapper = new Mapper($db);
$file = new \stdClass;
$file->id = 3;
$mapper->invoice_file->remove($file);
$mapper->flush();
var_dump($mapper->getConnection()->getLastStatement()->rowCount()); // result from last executed statement
// or
var_dump($db->getLastStatement()->rowCount()); // result from last executed statement
// or
var_dump($db->affectedRows()); // it encapsulate result from last executed statement hey, core developers, @Respect/core do you have any different idea how to do it? |
Tks again @tonicospinelli, I did some changes in my repo fork, something like that you said about get the last statement in each |
@tonicospinelli I agree with your suggestion, specially because making The major problem I see is that the
|
thanks, @augustohp this way is good approach for me! it could be encapsulated with |
Thanks @tonicospinelli and @augustohp, I've built some unit tests and getting each |
Hi Guys,
How about return the number of affected rows when run Mapper remove method? Is it possible (currently) or interesting to everyone in a new PR?
The text was updated successfully, but these errors were encountered: