TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.94k stars 173 forks source link

select empty if no relation? #428

Closed samnymr closed 1 year ago

samnymr commented 1 year ago

Hiya

So i've trying to allow users to relate products to products without having to do any extra tables

I've tried both of these below:

  # select :shop_the_look_product_ids, Product.all, { label: "Category" }, multiple: true
  # collection_select :shop_the_look_product_ids, Product.all, :id, :name, { label: "Category" }, { multiple: true }

both are saving into the database as ["", "6", "7"] but for whatever reason when looking at the field in the admin it shows as blank?

some help with this would be amazing!

spohlenz commented 1 year ago

Could you share a bit more of what your tables, models and relations look like? From "without having to do any extra tables", I'm guessing you are possibly using an array DB column and not using a regular Rails has_many?

samnymr commented 1 year ago

As I came to reply I just solved it, again thinking this was me being stupid, Ended up having to do a string in the database with array: true and it worked first time...