I have problems with creating a query that can relate 4 tables.

This is the schema: 

"users" - | id |

"snippets" - |id| user_id |

"snippets_has_tags " - |snippets_id | tags_id| 

"tags" - | id | name | description|

I would like to be able to consult the amount of tag that all the snippets 
of a user have and also be able to count the repetitions of these tags, i 
mean,
if in a user snippet is the tag "javascript" and in another "javascript" 
and also "python"
I want the query to return:

(javascript, 2), (python, 1)

This is the code:

DB[:users]
  .join(DB[:snippets], user_id: Sequel.qualify(:users, :id))
  .join(DB[:snippets_tags], snippet_id: Sequel[:snippets][:id])
  .join(DB[:tags], id: Sequel[:snippets_tags][:tag_id])
    .where(:user_id=>user.id).select(:name, 
Sequel[:tags][:description]).all.to_json


But, i get this exception: *Sequel::DatabaseError: SQLite3::SQLException: 
no such column: snippets.id*

As you can see, I have not even implemented count () to count the tags, 
because the code does not work, the exception appears in the second join.

I would appreciate any possible help, at least, to understand what I am 
doing wrong and to make this current query work. Thank.


*ps: This is the most complicated query I've tried to do with the ORM.*

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to