Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
acts_as_reportable: duplicate records returned when two models used with :include
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
gluis  
View profile  
 More options May 22 2009, 7:53 pm
From: gluis <louisju...@gmail.com>
Date: Fri, 22 May 2009 16:53:18 -0700 (PDT)
Local: Fri, May 22 2009 7:53 pm
Subject: acts_as_reportable: duplicate records returned when two models used with :include
hi all,

i'm getting some strangeness w/ acts_as_reportable. short question: is
there a way to ensure a query is only run once? see below for why i
ask: (btw, although this is a longish question, i only put in relevant
info)

assume 3 models
Event, has_many :members, :through => :registrations AND
has_many :registrations
Registration, belongs_to :event AND belongs_to :member
Member, has_many :events, :through => :registrations AND
has_many :registrations

STRANGENESS 1:

running this query:
Member.report_table(:all, :only => [:first], :include => {:events =>
{:only => [:id]},:registrations => {:only => [:event_id, :id]}})

returns duplicate records for any member registered for more than one
event. *and* it returns mixed up id columns for events on the
duplicates (i.e. the first two rows have the correct data):

sample output of this query (pls excuse the formatting):
+-------------------------------------------------------------------------- ------
+
| first | registrations.id | registrations.event_id | events.id |
+-------------------------------------------------------------------------- ------
+
| Jo    |               11 |                                 1
|         1 |
| Jo    |               13 |                                 2
|         1 |
| Jo    |               11 |                                 1
|         2 |
| Jo    |               13 |                                 2
|         2 |
| Juan  |                  |
|           |
+-------------------------------------------------------------------------- ------
+

STRANGENESS 2:

if you run the same query on a different model, the correct results
are returned!:

Event.report_table(:all, :only => [:id], :include => {:members =>
{:only => [:first]},:registrations => {:only => [:event_id, :id]}})

+-------------------------------------------------------------------------- ----------
+
| id | members.first | registrations.event_id | registrations.id |
+-------------------------------------------------------------------------- ----------
+
|  1 | Jo            |                                   1
|                   11 |
|  2 | Jo            |                                   2
|                   13 |
+-------------------------------------------------------------------------- ---------
+

all member names are unique, and members cannot register > once for
the same event.

is this a known issue w/ acts_as_reportable? or am i composing the
query improperly? why the different results for two models who have
similar characteristics? (i.e. both Member and Event have has_many
<each other> :through => :registrations; both have the same
relationship type to Registration, i.e. Registration
belongs_to :member, :event)

STRANGENESS 3:

if i run the query with only one model included (i.e. :include =>
{:events} OR {:registrations}), i get the proper results.
also, running the query w/ :conditions, e.g. a specific name, returns
the same duplicate record output, except only that name appears (as it
should).

is there a work around? is it acts_as_reportable, or ruport? i haven't
seen mention of this anywhere. is it has_many through? is habtm better
for ruport? is there something in my Member model? it's a pretty
vanilla model, w/ two mixins besides acts_as_reportable: Authlogic and
a custom module to facilitate custom searches in SQL. As the Event
model has the same custom module, i removed Authlogic integration for
yucks, but the same strangeness occurs without it.

any help, hints, URLs, etc. are much appreciated,

louis


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew France  
View profile  
 More options May 23 2009, 4:35 am
From: Andrew France <andrew+li...@avito.co.uk>
Date: Sat, 23 May 2009 09:35:26 +0100
Local: Sat, May 23 2009 4:35 am
Subject: Re: [ruport] acts_as_reportable: duplicate records returned when two models used with :include

I think the behaviour is correct because you are including 'events'
twice via the HABTM :through. You would probably want a nested include:
:include => {:registrations => {:only => [:event_id, :id], :include =>
{:events => {:only => :id}}}}

Acts As Reportable has no SQL knowledge it just walks the ActiveRecord
object graph so it doesn't know that the two separate associations go to
the same table. If you look at the generated SQL it probably has two
joins to the same table.

I don't know why the behaviour would be different in your second
example, but it is data-dependent.

> STRANGENESS 3:

> if i run the query with only one model included (i.e. :include =>
> {:events} OR {:registrations}), i get the proper results.
> also, running the query w/ :conditions, e.g. a specific name, returns
> the same duplicate record output, except only that name appears (as it
> should).

Not even sure what the question is with this one :). I don't know what
version of AAR you're using, I'm guessing the gem from RubyForge. You
might find it useful to install the latest from GitHub either as
vendor'd source or using the GitHub gems service. If you do, please let
me know if it solves any of your problems or if it introduces any new ones!

http://github.com/ruport/acts_as_reportable/tree/master

Hope that helps,
Andrew


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gluis  
View profile  
 More options May 26 2009, 1:10 pm
From: gluis <louisju...@gmail.com>
Date: Tue, 26 May 2009 10:10:46 -0700 (PDT)
Local: Tues, May 26 2009 1:10 pm
Subject: Re: acts_as_reportable: duplicate records returned when two models used with :include
thanks, andrew. i would have replied sooner, but i was offline all
weekend. i'll test this today.

ftr, i'm using ar 2.3.2

the third strangeness was just pointing out that if i only include one
model, it works as expected.but if i do the equivalent of a 'where'
clause by using :conditions, that the same duplication of records
happens. e.g. :include => :events...., :conditions => [':event_title
= ?', 'something']

l

On May 23, 4:35 am, Andrew France <andrew+li...@avito.co.uk> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gluis  
View profile  
 More options May 26 2009, 1:23 pm
From: gluis <louisju...@gmail.com>
Date: Tue, 26 May 2009 10:23:00 -0700 (PDT)
Subject: Re: acts_as_reportable: duplicate records returned when two models used with :include
well, this works (nesting). thanks! one note, i get some warnings
before the results, which might be of interest to you as the
maintainer:

/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
associations/association_proxy.rb:221: warning: default `to_a' will be
obsolete
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
associations/association_proxy.rb:221: warning: default `to_a' will be
obsolete
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/
associations/association_proxy.rb:221: warning: default `to_a' will be
obsolete

(i'm using 1.8.7)

i'm using the aar version you recommended in another post (which fixed
another issue i had) as a plugin. it says 1.1.1 in the source, but the
gem from rubyforge also says 1.1.1. it's the one from github.

thanks for the pointer/help!

louis

On May 23, 4:35 am, Andrew France <andrew+li...@avito.co.uk> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google