Connecting Tables in the Admin

edited December 2014 in Modules
I have 3 tables, products, products_to_categories, and categories. When I add a new product via the admin, I want to have the ability to add and save the categories that that the products belong to. I am having a brain freeze about what I need to do to make this happen. I went through the documentation and well as looking through the blog module but nothing is triggering that "oh, this is what I need to do". Any guidance would be greatly appreciated.

Comments

  • edited 7:03PM
    FUEL has a built in relationships table that it uses for it's has_many and belongs_to relationships. This means you won't need a products_to_categories table. However, you can set your model to save to a different table (which requires 5 fields, one for each table and column it is saving to plus the ID field). The documentation has more here:
    http://docs.getfuelcms.com/general/models#relationships
  • edited 7:03PM
    Thanks. This is exactly the push in the right direction that I need. Jumping between applications and frameworks and such sometimes throws me into a tailspin and I just need a little assistance on getting out of it.
  • edited 7:03PM
    It seems that if I multiple items in the has_many array and each item uses a different association table (already had the tables and just added the extra fields to each table to save time so I didnt need to update all the spots in the code where changes would need to be made), it doesn't recognize the different association tables. Example, if one has_many item uses the products_to_categories table and the other uses products_to_sciences table, only the values from the products_to_categories table is being pulled and those values are being associated not only to the products_to_categories table but to the products_to_sciences table as well. I double/tripled/quadrupled check to make sure they were configured differently too in the has_many array too. Does this make sense?
  • edited 7:03PM
    Do you have some example code to try and replicate the problem. Also, are you needing your own relationships tables or can you just use the default fuel_relationships table?
Sign In or Register to comment.