I have an organization table for example
ID, name, address, phone, email, etc...
Now I want to add multiple addresses, phones and emails.
Is it a good way to store json data in email column like this
[ "[email protected]", "[email protected]", "[email protected]" ]
Or create another table just for emails and another for phones etc...
If storing json data is better - what is the best way to use it in rails?
Here is what I found
http://api.rubyonrails.org/classes/ActiveRecord/Base.html
Saving arrays, hashes, and other non-mappable objects in text columns
Storing data as a JSON string in a single database field means that you will not be able to manipulate/query the data using SQL - which kind of defeats the point of storing the data in a database, you may as well store it in a text file.
I'd recommend a one-to-many relationship between your organization table and tables for email addresses and phone numbers. See video explaining different relationship types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With