I have a question regarding ordering datasets with sequel.
I have tables 'jobs', 'users', 'comments'. Users can apply for any job, so I have a many-to-many association here (I also have a 'jobs_users' table). Jobs and comments represent one-to-many association. What I'm trying to implement is the following - I'd like to retrieve rows form 'jobs', ordered by:
Number of users applied;
Number of comments (most commented first).
I use sequel and so far I'm playing with explicit queries, so could you help me to implement such ordering in native sequel way?
Simplified db looks like this:
create_table :users do
primary_key :id
String :nickname
end
create_table :jobs do
primary_key :id
Text :description
end
create_table :jobs_users do
primary_key :id
foreign_key :job_id
foreign_key :user_id
end
create_table :comments do
primary_key :id
Text :comment
foreign_key :user_id
foreign_key :job_id
end