> Hello kranthi,
>
> I forgot to them you what is the actual problem... sorry...
>
> The problem is the although I add the include parameters, the columns
> from the association are not fetched,
> For instance with the following line:
>
> data1 = Shop.report_table(:all, :only => [:id, :ret, :name], :include
> => {:prof=>{:only=>[:name]}, :sal=>{:only=>[:name]}})
>
> The columns I'm getting are :id, :ret and :name from Shop. The other
> columns from prof and sal table are not present in data1.
The syntax looks fine to me, can you let me know what version of
acts_as_reportable you are using (as it's separate to Ruport)?
Also the version of Ruby might be useful.
If you're using the standard gem you might want to try the latest from
Github (below) as I'd be interested to see if that makes any difference.
http://github.com/ruport/acts_as_reportable/tree/master
Regards,
Andrew
> I'm using acts_as_reportable 1.1.1 and ruby 1.8.6.
> I've tried the latest version as you suggested but the problem
> remains...
I have no idea what it could be, I think the following information would
be useful if you're able to provide it:
- Brief code excerpts showing the relevant model relations (has_many
:profs etc).
- First few lines of the report_table text table output.
- Confirming that the SQL in the log is as you'd expect and samples if not.
- Does it work without the :only part? (i.e. you get all included cols)
If the code samples are very short you can put them in an e-mail, but
anything longer please use a pasting service like gist.github.com or Pastie.
Thanks
> The relations were to records that were deleted. If I change them to
> existent records from the other tables it works fine. I also found out
> that when the relation is null the columns names for that relation are
> not fetched.
>
> I understand that ruport cannot (obviously) get data that isn't there
> but shouldn't it get at least the columns names from the relations?
AAR works by handing off the find parameters pretty much as-is to Rails,
then walking the object graph (following the includes) fetching the
attributes as a hash for each object, and then munging it into a table.
It doesn't know anything about the DB or Rails' reflection system.
The Github version fixes a problem where the columns go missing if the
first row (or maybe last, forget now) has the association missing even
if other records have the data. Which is clearly an unacceptable failure!
But if not a single record returns an association then AAR will never
see the appropriate column (key of the hash) so it won't be output. Not
entirely sure if this is reasonable behaviour or not. Would welcome your
and anyone else's comments.
I trust that it's all working now as long as there is data!
Best regards,
Andrew