HABTM's select clause

Is there any reason why HABTM default select clause is select * from ... rather than select table_name.* ... ? As it is attributes from the join table 'leak' into the attributes for the collection you are fetching (which for example makes a mess if you call to_xml on it). On the other hand has many through does do select table_name.*

Is there a specific legacy reason why this is so or is it just historical artificat (ie can we just change it to table_name.*)

Fred

This used to be a desired behavior; here's the note from the 1.1 changelog:

---- The method has been deprecated and removed for a while now, though.

Ah yes, that does make sense.

What attributes are "leaking" in your app? And how do you access them otherwise?

Not my app :slight_smile:

if you've got foo habtm bars then you get foo_id and bar_id attributes appearing, which you don't care about or ever want to access.

Fred

Frederick Cheung wrote:

---- The method has been deprecated and removed for a while now, though.

Ah yes, that does make sense.

Yeah, the behaviour has been 'frowned upon' for a while. Prior to the has_many through functionality it was a 'neat hack' for things like having created_at on some association.

Now it's kinda disgusting :slight_smile:

Could be worth removing it for 2.3 now as it's just bound to cause confusion and people can manually do :select if they want it.

Makes sense to me. Anyone desperately holding onto this bit of functionality ?

Fred

It’s funny because the functionality is the only thing omitted from the email.

-Mike

Frederick Cheung wrote:

If you don't know what it is, you probably don't need it.

Basically if you have an additional column in the join table, its value will appear as a magic attribute on the retrieved records.