Closed Bug 1383991 Opened 7 years ago Closed 7 years ago

Incorrect code in Express Tutorial

Categories

(Developer Documentation Graveyard :: Learning Area, defect, P5)

All
Other
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: freazeek, Assigned: cmills)

References

()

Details

:: Developer Documentation Request

      Request Type: Correction
     Gecko Version: unspecified
 Technical Contact: 

:: Details

you are using the following code in section about how to delete records:

if (results.authors_books>0) {

but it seems should be 

if (results.authors_books.length>0) {

I am not sure but at least the latest works in my case.

Anyway thanks for the tutorial)
I am not sure about this - I tested it with the code as it, as it worked for me. Did yours work when using results.authors_books>0 ?
Assignee: nobody → cmills
(In reply to Chris Mills (Mozilla, MDN editor) [:cmills] from comment #1)
> I am not sure about this - I tested it with the code as it, as it worked for
> me. Did yours work when using results.authors_books>0 ?

No, it doesn't work. And it doesn't work with the example published here: https://github.com/mdn/express-locallibrary-tutorial

How to reproduce:

try to delete any book without BookInstances, 
stop on the confirmation step (where the "Do you really want to delete this Book?" and delete button are shown)
create an instance of this book (on the other tab)
return to the confirmation step and press "Delete" button.

The book will be deleted, though it should not (as in this case there is a bookInstance without book, that leads to an exception).

BTW I have broken the database that your example uses (var dev_db_url = 'mongodb://cooluser:coolpassword@ds119748.mlab.com:19748/local_library'), as now there is a bookInstance without book and the "All book-instances" page shows an error.
(In reply to freazeek from comment #2)
> (In reply to Chris Mills (Mozilla, MDN editor) [:cmills] from comment #1)
> > I am not sure about this - I tested it with the code as it, as it worked for
> > me. Did yours work when using results.authors_books>0 ?
> 
> No, it doesn't work. And it doesn't work with the example published here:
> https://github.com/mdn/express-locallibrary-tutorial
> 
> How to reproduce:
> 
> try to delete any book without BookInstances, 
> stop on the confirmation step (where the "Do you really want to delete this
> Book?" and delete button are shown)
> create an instance of this book (on the other tab)
> return to the confirmation step and press "Delete" button.
> 
> The book will be deleted, though it should not (as in this case there is a
> bookInstance without book, that leads to an exception).
> 
> BTW I have broken the database that your example uses (var dev_db_url =
> 'mongodb://cooluser:coolpassword@ds119748.mlab.com:19748/local_library'), as
> now there is a bookInstance without book and the "All book-instances" page
> shows an error.

Hrm, interesting. It is weird that we didn't catch this one ;-|

Well, thanks for pointing it out. I've fixed it in the article text, and on the example repo.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Thanks )
Sorry. I don't want to bore you but you still need to update the following files:

bookController.js - if (results.book_bookinstances>0) {
genreController.js - if (results.genre_books>0) {
(In reply to freazeek from comment #5)
> Sorry. I don't want to bore you but you still need to update the following
> files:
> 
> bookController.js - if (results.book_bookinstances>0) {
> genreController.js - if (results.genre_books>0) {

Ah, I forgot about the exercises - these don't actually appear in the tutorials ;-)

I've updated them now in the GitHub repo
Thanks. And there are two minor things about bookinstance_form.pug view.
- the status of a bookInstance is wrong when this bookInstance is updated
- the book of a bookInstance is wrong when this bookInstance is updated

 I have created a pull request: https://github.com/mdn/express-locallibrary-tutorial/pull/7. But sure that you can provide a more elegant solution )

Regards.
You need to log in before you can comment on or make changes to this bug.