Hi,

How can I count a many_to_many relations when retrieving the list?

Example:


#  models

class Artist < Sequel::Model(db[:artists])
    db[:artists]
  
    many_to_many(
      :albums, 
      class: Album, 
      join_table: :artist_albums,
      join_table_db: db, 
      left_key: :artist_id, 
      right_key: :album_id
    )
  end

  class Album < Sequel::Model(db[:albums])
    db[:albums]
  
    many_to_many(
      :artiss, 
      class: Artist, 
      join_table: :artist_albums,
      join_table_db: db, 
      left_key: :album_id, 
      right_key: :artist_id,
    )
  end


# What I want:

artists = Artist.all
# here I would love to have a field on each artist that gives me the
# count of the associated albums. e.g. artist.album_count 
# Is there a way to fetch it once and not cycling to each artist fetched 
# and query for that one

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/5fc7afd9-c962-4e59-be6e-ed846abda0f7n%40googlegroups.com.

Reply via email to