How can union-find algorithm be used with "real" data
Short answer: indirection.

For instance, each object could have a field that contains an index into the id array.

Or, you could use pointers.  Standard union-find data structures often use pointers instead of integers/indices/arrays.  Thus, each object has a pointer to another object in the same equivalence class.  See, e.g., https://en.wikipedia.org/wiki/Disjoint-set_data_structure or other standard presentations of union-find data structures.