sequel-combine
sequel-combine copied to clipboard
Provide inferring datasets
The question is strictly related to convenience of using sequel-combine. Actually combine-sequel works properly if column names are unique in a set of used relations, but if child and parent relations will have the same column, the query will don't return results in any "combined" objects.
For example:
DB[:groups].combine(many: { users: [DB[:users], id: :group_id] })
#=> SELECT *, (SELECT row_to_json(ROW) FROM (SELECT * FROM groups WHERE (group_id = id)) AS ROW) AS group FROM users"
If group_id column exist only in users table, query will works perfectly.
If group_id column exist(for some weird reasons) in both tables, the query doesn't specify which column is desirable.
Possible solutions:
- Auto inferring datasets by sequel-combine where an order of keys
id: :group_idis important.
DB[:groups].combine(many: { users: [DB[:users], id: :group_id] })
#=> SELECT *, (SELECT row_to_json(ROW) FROM (SELECT * FROM groups WHERE (users.group_id = groups.id)) AS ROW) AS group FROM users"
- Manual inferring datasets by developer.
DB[:groups].combine(many: { users: [DB[:users], groups__id: :users__group_id] })
#=> SELECT *, (SELECT row_to_json(ROW) FROM (SELECT * FROM groups WHERE (users.group_id = groups.id)) AS ROW) AS group FROM users"