Created by: gracewashere
title_attribute
was being used to display a link to each resource
throughout the dashboards.
It was acting as a kind of unique identifier, but was restrictive in several ways:
- The title_attribute had to correspond with a method on the model. It couldn't be computed from several methods.
- Only the current dashboard could look up the correct method for displaying a resource. This causes problems for relationships like the BelongsToAdapter and HasManyAdapter, which need to know how to display other objects.
Moving to #to_s is good in several ways:
- It makes representing an object super easy, with a single consistent method to call on each object.
- It encourages developers to write good
#to_s
methods on each of their objects.
And bad in several ways:
- If
#to_s
is not defined on a model, it defaults to the object's ID. This is not tied in any way to the database, so an object's identifier wouldn't be consistent throughout the dashboard. - If the user hasn't defined
#to_s
on a model, it doesn't noisily fail by default. If we wanted to noisily fail, we'd have to check against the default#to_s
string and raise an error.
To fix the bad effects, there's room for a separate gem that generates
better default #to_s
methods for objects, by trying for attributes
like name
or title
, and defaulting to id
if those are not present.