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