There is a table with fields: id, name, id_cat
Please show an example of a method that outputs these categories. And where you want to implement this method in the controller or in helpers? Help implement this recursive method.
There is a table with fields: id, name, id_cat Please show an example of
Share
As I correctly understand you have Category table with circular reference realised by column id_cat.
Following model should works as you expected:
So if
categoriestable looks like:Category.find(1).subcategoriesreturns array withcat 1.1andcat 1.2objects.Category.find(1).supercategoryreturnsnilCategory.find(3).supercategoryreturnscat 1objectCategory.find(4).supercategoryreturnsnil…