[rspec-users] RSpec makes me want to write better code
ashley.moran at patchspace.co.uk
Fri Sep 26 11:28:16 EDT 2008
On 26 Sep 2008, at 12:49, Matt Wynne wrote:
> Would you mind elaborating on why you don't like these? I'm pretty
> new to rails (but not programming generally) and rather naive about
> such things!
It's quite hard to explain briefly, but basically it makes the
predicate (interpretation of the table) extremely difficult.
A normal table like
Could be interpreted as "The car with reg plate <reg_plate> was bought
by the person with ID <owner_id> on <purchase_date>" (ok, they might
have sold it since, but...)
However, from the Rails wiki:
addressable_type # <- is a string
How do you interpret this? The relationship is fundamentally
different depending on the value of addressable_type, and is much
harder to enforce as an integrity constraint*.
There's another angle you can take, based on data types - you can
define a type PERSON_ID for the attribute 'owner_id' (and re-use it in
the 'departments' table as 'manager_id'), but the type of
'addressable_id' depends on the value of 'addressable_type'. How can
a value not know its own type?
"The person called <name> wants items delivered to the address with ID
<delivery_address_id> and invoices delivered to the address with ID
> Also why is the article so down on STI? What are the drawbacks? What
> do people use instead?
I'll reply to Mark...
* pah, who needs their data integrity protected anyway?
More information about the rspec-users