On Friday, May 5, 2017 at 7:20:07 AM UTC-7, Ramon Marco Navarro wrote:
>
> Hello,
>
> Given the following models:
>
> class Album < Sequel::Model
> many_to_one :artist
> end
>
> class Artist < Sequel::Model
> one_to_many :albums
> end
>
> I want to be able access a "virtual column" `artist_name`:
>
> album.artist_name == album['artist_name'] == album.artist.name
>
> Currently, I am using a after_load callback on the association to add
> these virtual columns to @values and also a before_save hook to remove
> them. Is there a better way of doing this in Sequel?
>
I would just define the artist_name method like this:
class Album
def artist_name
artist.name if artist
end
end
That does mean you wouldn't be able to use album['artist_name'], but in
Sequel it's expected to call methods for virtual columns.
Thanks,
Jeremy
--
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.