Help with act_as_reportable

21 views
Skip to first unread message

Tygo

unread,
Jul 15, 2009, 7:22:12 PM7/15/09
to Ruby Reports
Hello all,

I'm trying to use act_as_reportable with the include option but can't
seem to put it to work.
I want to be able to fetch only some columns from one table and some
other columns from associated tables.
Example: columns id, ret and name from model Shop, name column from
prof and name column from sal.

I'm tried in several different ways (using symbols and text) but they
don't work:
data1 = Shop.report_table(:all, :only => [:id, :ret, :name], :include
=> {:prof=>{:only=>[:name]}, :sal=>{:only=>[:name]}})
data3 = Shop.report_table(:all, :only => ["id", "ret",
"name"], :include => {:prof=>{:only=>["name"]}, :sal=>{:only=>
["name"]}})
data4 = Shop.report_table(:all, :only => [:ret, :name, :id], :include
=> :prof)

The only ways I can put it to work is if I don't include any columns
from the Shop model except the id column.
The following examples work but they don't return the columns I need:
data6 = model.report_table(:all, :include => {:prof=>{:only=>
["name"]}, :sal=>{:only=>[name"]}}). For instance, the following lines
work but they don«t return the columns I want.
data7 = Shop.report_table(:all, :include => :prof)
data8 = Shop.report_table(:all, :only => "id", :include => "prof")
data9 = Shop.report_table(:all, :only => "id", :include => {:prof=>
{:only=>["name"]}, :default_sal=>{:only=>["name"]}})

Can anyone help me?

Thanks!

kranthi reddy

unread,
Jul 16, 2009, 1:38:54 AM7/16/09
to ruby-r...@googlegroups.com
Hi,
I'm not really very sure why the report_table is not working but I can suggest you  an alternate way. You can use the native report_table_by_sql.And aslo re-check with the associations just to make sure everything is in place.
--
Thank you
kranthi
http://monkeydevel.wordpress.com

Tygo

unread,
Jul 16, 2009, 2:40:36 AM7/16/09
to Ruby Reports
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.

I will try the report_table_by_sql as you suggested.

Note: I'm using ruport 16.1.

Thanks.
Best regards,
Tygo

Andrew France

unread,
Jul 16, 2009, 1:06:30 PM7/16/09
to ruby-r...@googlegroups.com
Hi Tygo

> 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

Tygo

unread,
Jul 17, 2009, 2:57:10 AM7/17/09
to Ruby Reports
Hello 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...

Thanks.
Best regards,
Tygo

Andrew France

unread,
Jul 17, 2009, 10:01:49 AM7/17/09
to ruby-r...@googlegroups.com
Hi Tygo,

> 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

Tygo

unread,
Jul 17, 2009, 3:45:27 PM7/17/09
to Ruby Reports
Hello Andrew,

I think I found the problem!

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?

Here is the model code:

class Shop < MyActiveRecord

acts_as_reportable

belongs_to :prof, :class_name => 'DefaultProf'
belongs_to :sal, :class_name => 'DefaultSal'

end

Note: MyActiveRecord extends ActiveRecord::Base.

The SQL in the log seems to be ok.

Thanks.
Best regards,
Tygo

Andrew France

unread,
Jul 17, 2009, 7:31:11 PM7/17/09
to ruby-r...@googlegroups.com
Hi Tygo,

> 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

Tygo

unread,
Jul 19, 2009, 5:25:11 AM7/19/09
to Ruby Reports
Hello Andrew,

Yes, all is working fine.
Thanks for the explanation. I can easily work around the fact it does
not return all column names in this situations.

Best regards,
Tygo
Reply all
Reply to author
Forward
0 new messages