Skip to content
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

Blogger2: No mention of 'dependent: :delete_all', which seems necessary #1251

Open
jinjagit opened this issue Sep 23, 2018 · 0 comments
Open

Comments

@jinjagit
Copy link

jinjagit commented Sep 23, 2018

EDIT [Just realized these problems may be due to me using Rails 5.2.0, not 4.0.0 as in the tutorial. if so, sorry :-)]

After creating comments and tags functionality, the delete article function breaks. A solution is to edit the article.rb file to include;
dependent: :delete_all
in the lines:

has_many :comments, dependent: :delete_all
has_many :taggings, dependent: :delete_all

I discovered this by comparing my work to other students', since I found no explanation of this in the tutorial itself. I hate blindly copying stuff I have not understood, and since this is likely to be the first Rails app development done by us students, this seems to be a flaw (that might well confuse and demotivate).

Similarly, to be able to delete tags, tag.rb needs to include the line:

has_many :taggings, dependent: :destroy

Again, this is not explained in the tutorial, nor the related concept(s). I did find a StackOverflow post that touched on this, however (after laboriously checking all my files against another student's, and then googling the 'dependent: :destroy' term!).

Is this best practice? How do these terms solve the issues that not having them creates (Foreign key errors)? It seems unlikely that most beginner students will find these solutions, never mind understand them.

@jinjagit jinjagit changed the title No explanation of 'dependent: :delete_all', which seems necessary Blooger2: No explanation of 'dependent: :delete_all', which seems necessary Sep 23, 2018
@jinjagit jinjagit changed the title Blooger2: No explanation of 'dependent: :delete_all', which seems necessary Blooger2: No mention of 'dependent: :delete_all', which seems necessary Sep 23, 2018
@jinjagit jinjagit changed the title Blooger2: No mention of 'dependent: :delete_all', which seems necessary Blogger2: No mention of 'dependent: :delete_all', which seems necessary Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant