active_record has_many, :through and active _resource
Hello, I have many to many relationship between Venue and Catalog
class Venue :venue_catalogs end class VenueCatalogwhen I call url /venues.xml I get undefined method `quoted_table_name' for Catalog:Class
seems belongs_to HyperActiveResource is not recognizing catalog is not an ActiveRecord.
Quick answer: HABTM relationships are not yet implemented. Same with the :through attribute.
Longer answer: Active Record makes the assumption that a HABTM object is another Active Record., and expects it to respond to stuff like "quoted table name" - it will, in fact, try to build a select statement using joins to get your catalogs... which is obviously not what you intend here.
I've not yet implemented HABTM or :through and haven't yet looked at how they are implemented as they're somewhat more complex than the simple relationships.
For now, all I can suggest is not trying to use :through on an Active Resource. Instead fetch the set of catalogs out of your venue_catalogs using a hand-coded method. Possibly something as simple as:
def catalogs
venue_catalogs.map &:catalog
end
though I clearly haven't tested this code so it may not work - use with common sense ;)
Cheers, Taryn
thanks for the tip. that worked. but i am puzzled by this line venue_catalogs.map &:catalog what does it do?
is an equivalent of venue_catalog.map {|v| v.catalog }?
Yep - it is just that. It's a bit of ruby magic that makes a Proc out of the given symbol. Really neat if all you're doing in the map is just a single, known, named method.