Alanaktion / phproject

A high performance full-featured project management system
https://www.phproject.org
GNU General Public License v3.0
388 stars 106 forks source link

Adding a new 'Category' field to database #365

Open GelLiNN opened 5 years ago

GelLiNN commented 5 years ago

Hi phproject!

I've had some great success customizing this application so far, but I'm running into a headache with trying to add a new issue field to the database and the application as a whole.

I'm adding a new 'category_id' entry to the issue table, and a new 'issue_category' table with int IDs and category names. I have 5 categories and I'm going to add the ability to filter by those to the issue browser.

I have already changed the database.sql file to include these new changes and it works great, and have also changed the edit-form.html view to include a dropdown for selecting category, which populates from the database correctly.

The problem is that when I create the new issue or attempt to edit/update the issue, the new category does not make its way into the issue table. Also, on the single.html view when I attempt to display the category with @issue.category it comes back with a 500 field does not exist error.

Any fixes for this or help on implementing these categories would be greatly appreciated! categories4 categories3 categories2 categories1

Alanaktion commented 5 years ago

Due to a limitation in the Fat-Free framework, the code for the most part doesn't directly use any SQL JOINs in the model system. Because of that, we use a View instead of joins to get the additional issue data, but the view has its own defined set of columns to display. You'll need to update the issue_detail view in your database to include your new category column, then it should work everywhere.

GelLiNN commented 5 years ago

Thanks for the tip, I added the update to the issue_detail view to support the new field. However, now when I create the issue the database still is not updating and now the single.html view isn't rendering correctly and not displaying an error message either.

Here's the commit, maybe you will know what's causing this strange behavior on the client-side? https://github.com/Building-Intellect/BI-projects/commit/859ee6137461d8a352969b9600b48135494aaef7

Maybe the field has to be non-null? Or maybe something else with the way the fields are being saved in the db from the controller.

GelLiNN commented 5 years ago

UPDATE: I had the wrong name attribute on the form, and after fixing that the db auto-inserts the new category_id into the issue table. However, the single issue detail page is still just coming up blank and I have no idea why. category

Alanaktion commented 5 years ago

This could be a side effect of caching. Try clearing the cache from the Administration panel. If that doesn't work, check the PHP error logs, which should have more detail on what's going on.

GelLiNN commented 5 years ago

Okay I tried clearing cache and that didn't work, so I looked at the PHP error log and it's getting an "undefined field category" on $this->_render("issues/single.html"); in the single() method in the issues controller. Here's the callstack: [12-Nov-2018 22:35:59 UTC] Undefined field category [12-Nov-2018 22:35:59 UTC] [vendor/bcosca/fatfree-core/magic.php:85] DB\SQL\Mapper->get() [12-Nov-2018 22:35:59 UTC] [tmp/1y6t2lfaoikg0.38cruea1dj40g.php:133] Magic->offsetget() [12-Nov-2018 22:35:59 UTC] [tmp/1y6t2lfaoikg0.3u184if14tq8s.php:15] Preview->render() [12-Nov-2018 22:35:59 UTC] [app/controller.php:74] Preview->render() [12-Nov-2018 22:35:59 UTC] [app/controller/issues.php:798] Controller->_render() [12-Nov-2018 22:35:59 UTC] [index.php:146] Base->run()

After looking up the error online I haven't found anything. Any idea what could be causing this given the new info?

Thanks again man, here's a link to my current codebase if you want to chase anything down: https://github.com/Building-Intellect/BI-projects