Hi all,
I’m having problems creating a query.
I have an event that has many attendees
events_table: id, name
attendees_table: id, user_id, event_id, present
I want to create a query that shows all the events to a user and if he
will be present (the user can add/change his presens). If he hasn’t
yet added his presense than there is no record in the attendees table
ofcourse
An example of a queryresult can look like:
events.id | attendees.user_id | attendees.present
1 2 1 <–
will be present at event 1
2 2 null <–
has not yet stated his presense at event 2
3 2 0 <–
will not be present at event 3
Someone has an idea?
Thanks,
Stijn
Tarscher wrote:
Hi all,
I’m having problems creating a query.
I have an event that has many attendees
events_table: id, name
attendees_table: id, user_id, event_id, present
I want to create a query that shows all the events to a user and if he
will be present (the user can add/change his presens). If he hasn’t
yet added his presense than there is no record in the attendees table
ofcourse
An example of a queryresult can look like:
events.id | attendees.user_id | attendees.present
1 2 1 <–
will be present at event 1
2 2 null <–
has not yet stated his presense at event 2
3 2 0 <–
will not be present at event 3
Someone has an idea?
Thanks,
Stijn
this should look a bit like this
user model:
has_many :attendees
has_many :events, :through => :attendees
attendee model:
belongs_to :user
belongs_to :event
event model:
has_many :attendees
then a simple
@user.events
should return all records for which the user has an attendees record
and @user.attendees[0].present gives his presence
eg in view:
<% @user.attendees.each do |attend| %>
- <%= attend.event.name %><% "is present" if attend.present
%>
<% end %>
hope i didn’t miss an important point
You are right. That is much better.
1 question thuogh:
maybe attendee is not a good name because calling it attendee and also
using it for not attending the event is a bit weird I think.
I’m looking for a suitable word but my English fails me. Maybe you
have a suggestion?
Thanks
Stijn
On 21 dec, 15:28, Thorsten M. [email protected]
participant
subscriber
would be alternates to attendee
but i would use ‘registrations’ or ‘enlists’, since that’s better
describing that it links an user with an event