What is the proper way of editing foreign keys in-line in the CMS?
  • I have a table with around 20 columns. Say the name is 'table1'.

    I've been thinking of changing that so that each entry in the table has links to 20 rows in a different table ('table2'), which is basically a key/value store (so contains three columns only: table1_id, key, value).

    If I did that using `$has_many` in my `Table1_model`, I'd probably end up with 20 dropdown menus, and editing each of them would open up a new modal window etc, requiring quite a lot of mouse clicks.

    Is there an easier way to do this? Or do I need to manually load everything from the database in `form_fields`, set up the field names ensuring they're distinct, and then insert/update rows in `table2` in one of the "hook" methods?

    That's essentially what I did in my "translatable" module:



    Is there a more elegant way to do this in FuelCMS?
  • There is a $foreign_keys = array(); property on the model you can set to the column name(s) that are foreign keys to other models.
  • Hey David, thanks for the reply. Wouldn't using $foreign_keys yield the same result thugh? I mean the database structure would be slightly different as it'd use the fuel_relationships table, but in terms of display, the fields would look the same either way right?

    I dug around the source code a bit and found that when layout variables are displayed in the `Pages` view, it does kind of something similar where the variables are all POSTed with names pre-fixed with a special string (I think it was `vars--`), and then re-processed on the other end.

    I guess stripping that functionality out would be quite a task though :-( As I understand Layouts in FUELCMS are only used for pages, and cannot be used in any module.
  • That's correct about layouts to some extent. There are block layouts that can be used for modules. But the template field type may also be of some use for you because you could essentially create a repeatable template that has all the fields you need listed and you won't have to click to open a modal to edit. You would have to do a database query to pull in the values from your table to populate each repeatable fields "values" parameter:
  • Thanks a lot for the pointers. I'll give this a go soon and report back :-)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!