Move categories with command line

Is there a command for moving categories to be sub-categories?

And can a number of them be sun in a script?

1 Like

Something like this might do it.

parent=Category.find_by_slug('slug')
subs=Category.where(<a way to get your categories>).update_all(parent_category_id: parent.id)
4 Likes

Thanks. It took me a while to figure out what was meant by “a way to get your categories”, but realised it probably was the “where” clause of a SQL statement. Though I had no idea what the table names or column names were, but managed to find them with the SQL statements noted in the post about the Data Model.

So, I ended up with this,

parent=Category.find_by_slug('csgnet') subs=Category.where('slug like “csg1%”').update_all(parent_category_id: parent.id)

which moves all categories starting with the text “csg1” into the category “csgnet”, where “slug” is the column name in the table of categories. The table name is called “category”, I think.

1 Like