What is an efficient and elegant way of performing a "find_or_create_all" in rails?
Given:
names = ["Bob","John","Jack","Sid"],
Users table
Needed:
users = ["#User:0x3ae3a00", "#User:0x3ae3938", "#User:0x3ae3898", "#User:0x3ae37f8"]
where a user is created only if it doesn't exist.
An intermediate solution - ["#User:0x3ae3a00", nil, nil, "#User:0x3ae37f8"] will also do, if for example only the first and fourth entries exist in the Users table.
One way is to use a find_all_by_name and use a hash to map back to the entries in the names array but I wonder if there is an elegant yet efficient way in rails.