Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide inferring datasets #4

Open
wmaciejak opened this issue Jun 7, 2017 · 0 comments
Open

Provide inferring datasets #4

wmaciejak opened this issue Jun 7, 2017 · 0 comments

Comments

@wmaciejak
Copy link
Owner

wmaciejak commented Jun 7, 2017

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:

  1. Auto inferring datasets by sequel-combine where an order of keys id: :group_id is 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"
  1. 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant