Replies: 2 comments 19 replies
-
If you call Artist.
eager(:artists).
where(Sequel.like(:name, "%#{artistPattern}%")).
all do |artist|
p artist.name
p artist.albums.map(&:name)
end |
Beta Was this translation helpful? Give feedback.
9 replies
-
The 'put"'s, above, should be "puts" but it doesn't seem to matter. "puts" gives the same (except for displaying "put" rather than "puts") as i posted. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been playing with this for a couple days... getting some thing to work (finally)... but perhaps not the right way. If so, i hope someone will tell me how it should be done. Anyway, same models as i posted before in Discussion #2224... i have a pattern to match one or more artists in my 'artists' table, and i want to get the artist name, album name, path for the album directory, and maybe the year and whatnot to flesh out the line displaying this info. What i've come up with is:
The sequel 'qualify' ([][]) i just added in trying to get the info i want returned. It appears that the join causes the dataset returned to be a combination of artists and albums tables. What happens when i specify the select on the artist name, album name, album path, appears to be that all the album names are returned, followed by all the (corresponding) artist models (and i don't know what happened to the path info.), which is not what i want.
Here's my attempt to look at what the above returns:
o.name: Christmas, o.class: Artist
o.name: High_Winds_White_Sky, o.class: Artist
<snip... there are 30 albums, in all>
o.name: Small_Source_of_Comfort, o.class: Artist [#29]
o.name: Crowing_Ignites, o.class: Artist [#30]
#Artist:0x00007f739790a0a8
Followed by 29 more lines similar to that last one with slightly different internal identifiers for the Artist (even though the artist is the same in all cases... Bruce Cockburn, as i used as the matching pattern 'Cockburn'.
A question relating to all this is how you can look into a model object. I often want to see what i've got and "puts o" or "puts o.inspect" often just gives me the model name (Artist or Album), and an identifier and i've not been able to find a reliable way to look into the thing. Note that even though, above, i'm doing a 'puts' on o.name and o.class, for the last 30 of the 60 items being returned, it's just printing out '#<Artist: ...> -- which i don't get at all how that can be.
As always, any help (thanks Jeremy) is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions