Wes Gamble wrote:
> All,
>
> AS 2.1
> Rails 2.1
>
> I have two models, MedicalFacility and MedicalFaciiltyCategory which are 
> HABTM to each other.
>
> In the MedicalFacilityController, I pull both the MedicalFacility 
> records, as well as their related MedicalFacilityCategory records, using 
> a joins_for_collection like so:
>
>   def joins_for_collection
>     [:medical_facility_categories]
>   end
>
> When I get the result set back for the AS "list" action, the result set 
> hash has "id" set to the ID of the MedicalFacilityCategory and 
> "medical_facility_id" set to the ID of the MedicalFacility.  This is 
> fine in the sense that there is no conflict between the two "id" columns 
> in the result set.
>
> However, it is not acceptable. 
>
> What happens is that because "id" is the _category_ id, all of the 
> action links in the scaffold are using it to access the _facility_, 
> which is wrong.
> Similarly in the JSON output which is used by an iPhone client, the 
> client is pulling up the same _facility_ because it is using the same 
> "id" (from the category).
>   
It turns out that my problem has to do with an interaction issue between 
Geokit (the MedicalFacility model acts_as_mappable) and AS.  The custom 
finder processing for Geokit forces the SELECT clause in my AS join 
query to be SELECT *, whereas plain vanilla AS will correctly do SELECT 
medical_facility.*

Because I'm getting the SELECT *, the columns of the same name from the 
join table are overwriting the result set.

I have temporarily fixed this by hacking the result set using a method 
in MedicalFacilitiesController like so:

 def modify_AS_list_result_set
    @records.each {|r| r[:id] = r[:medical_facility_id]}
  end

and hacking list.rb (in AS) to make a callback to this method just 
before the rendering occurs.

I will look into patching Geokit or something else.

Wes

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to