Polymorphic association do they work out of the box in Hobo?

39 views
Skip to first unread message

Bob Sleys

unread,
Dec 27, 2011, 12:25:04 PM12/27/11
to hobo...@googlegroups.com
I thinking I need/want a polymorphic association but am unsure how to make it work properly in Hobo or even if it's supported at all.

I am trying to add reporting to an app.  I using Jasper Reports IReports and have a manually setup report working fine.  Now I want to try to expand it to work across the site.  I know it won't be able to be totaly app driven and I'll need to do some manual coding work for each report but I'm trying to limit the amount of hard coding as much as possible.

Now for each report to run it needs an XML file generated at run time.  This will have to be coded via an action on the appropriate controller and an associated .rxml file to format the xml file.  I don't see a way around this part being done manually.  At least no easily.

However once that is done all that is needed to run the report is to have the compiled report generated from IReport uploaded and a bit of additional info stored about each report.  All this could be stored in a Report model and a report controller in the admin sub site.  It's associating the report to the model it reporting on that I think I need to setup a polymorphic association to each of the models I want to report on.  I can then list a models reports in a side bar via this association.

I setup the polymorphic association with a single model to start.  The migration ran fine but when I got to the new page for a report I get the following error.

Showing controller: admin/reports; dryml-tag: new-page where line #1 raised:

wrong model name: "active_record/base" (extracted from translation key: "active_record/base.messages.none"). You might want to use the translate/t tag/method instead.

Bryan Larsen

unread,
Dec 27, 2011, 12:39:12 PM12/27/11
to hobo...@googlegroups.com
I've never used polymorphic associations but I suspect that they
shouldn't be hard to fix.

If you really want to help me fix them, fork
https://github.com/Hobo/agility-gitorial/tree/testing and add a
polymorphic association to it so I have something to test against as I
fix them up.

Bryan

kevinpfromnm

unread,
Dec 27, 2011, 12:55:02 PM12/27/11
to hobo...@googlegroups.com
The polymorphic association doesn't play nicely with form.  Usually I do something like an owner action for creation anyway.  Remove the _type and _id fields from the form and set them manually.

Bob Sleys

unread,
Dec 27, 2011, 2:45:26 PM12/27/11
to hobo...@googlegroups.com
Thanks for the tips guys however the more I think about it I don't want a true polymorphic association.  I need to associate a report to a model not a specific record in the model. So I think I just need to add text filed to the report model with a manual selection list of model names and then use that model current model name to query the reports that are associated with it perhaps with a named_scope on the report model.

Bob
Reply all
Reply to author
Forward
0 new messages