1

As specified in this other question you can store serialized data in the database. What i want to know is if i really should or just create a simple extra table.

Object has a list of asociated numbers.

Will probably need to check if an object has a particular number.

Will never update it.

Wont query it.

Have property numbers as serialize?

Have table Numbers belonging to Objects?

BTW im using rails 5.1 and postgresql.

Thanks

aza
  • 38
  • 7

1 Answers1

2

Since you're using PostgreSQL, you actually have a third option: use an array column.

Add the array: true option when creating the column:

t.integer :column_name, array: true

and then model.column_name will be a Ruby array and you can use all the PostgreSQL array operators and functions to work with and query the array.

I tend to think that you're usually better off with a separate table but an array column is often convenient and fairly easy to unroll into a separate table if necessary.

I'd stay away from serialize. That throws a blob of YAML into your database and YAML is difficult and cumbersome to query let alone manipulate inside the database.

mu is too short
  • 426,620
  • 70
  • 833
  • 800