1

I've a data model and i have an issue for executing a request.

Here's my model :

enter image description here

I would like to get all the expenses associated to one specific event.

Do you think that my model is wrong ?

For more explanations this is how i set my data in the data base : I have 2 types of event : 'Event' and 'Party'

A guest is associated to 1 or n expenses and an expense is associated to 1 or n guests. Thats why i've created my entity "Transaction".

A transaction has 2 types : "Paid" and "Beneficied" because a Guest can pay an expense and can be a beneficiary too.

Here's how i work with theses entities : For one expense in one event, a guest pays this expense for all the other guests, so i create a transaction associated to this guest and the expense with the type 'Paid' and a has many transactions as my event's guests associated to the same expense but with the type "Beneficied".

I don't know i'm very clear in my explonations...

EDIT

As people doesn't really understand my question, i'll explain how my application does work.

The main purpose of my application is to rebalance expenses between people for a party (birthday, sushi party, etc.) or an event (vacations, week-end, etc.).

My application is already on the Apple store : iVent. But it doesn't works very well that's why i want to update it using core data :).

So, how doest it work ?

The user create an event and select the type of the event

For a party :

I get the iPhone contact and show them on a tableview, the user check which contact is invited to the party.

Then for each event, i have a Grocery list. I get that grocery list from a plist which can be modify by the user as "Default grocery list". But, for each event, the user can delete all the groceries, it won't affect the plist.

My groceries are sorted by categories (Drinks, meals, furnitures, alcohols, etc.). The user selects which grocery he wants for example 2 six-packs, 3 bottle of Red wine etc. Then he links a Grocery to a Guest : Paul will buy 1 six-packs and 1 bottle of red wine, Amy 1 six-pack etc.

Then i allow the user to give the price for each assigned groceries and to set which guest is beneficiary for this grocery. For example Anna doesn't drink alcohol, so she doesn't want to pay for any alcohol when the user will rebalance all the price between the user.

For an event, the process is different :

The user only check the invited guest for the event creation. Then during the event the user will put in the data base all the expenses made.

For exemple Paul and Anna paid gas for everyone, so we set Paul and Anna as buyers of an expense and Paul, Anna, Maurice and Mike as beneficiary because they all were in the car for the trip.

We can set different prices for the buyers for example the gas cost 50$ then Anna paid 20$ and Mike 30$.

It's the same for the beneficiaries : For example Mike came only at middle of the trip so he will pay (after the rebalance) only 12.5% of the price for the gas and not 25% as default (because they were 4 in the car ^^)

I know it's a little confusing to understand but that's why i came here for help ^^

Basically that's how my application works, the version on the Appstore does already all of these features but not very well.

Here's my all data model :

enter image description here

I hope you'll understand now my problem :)

I'd like to know if my model is Ok and how can i list all the expenses for an Event (not a party) with this model configuration.

Pwyll28
  • 117
  • 11
  • This is not clear at all. Could you go into the purpose of the application as a whole? It might help people understand what you are asking for exactly – Pinwheeler Apr 10 '13 at 01:18
  • Ok i'll edit my question and explain how my application works :) – Pwyll28 Apr 10 '13 at 09:55
  • So here's what I'm understanding. You want to give the "Event" entity some way to access "Expense" entities? Why not create a relationship between event and expense? – Pinwheeler Apr 11 '13 at 21:08
  • @Pinwheeler Doesn't this make a redundancy ? Because for a "party", i have a category and a Grocery but not for an "Event" – Pwyll28 Apr 12 '13 at 08:12
  • Okay, I'm understanding you more and more. Right now, if you want to have an 'Event' have an 'Expense', it must first have a 'Guest' and that 'Guest' must have a 'Transaction'. Currently, there is no way for your 'Event' to have an 'Expense' on its own. Is this as intended? – Pinwheeler Apr 12 '13 at 17:03
  • @Pinwheeler Yes it's ! But transaction is created automatically with an expense! I use the transaction to differentiate the link between an Expense and a Guest when the guest is the buyers of the expense and when he's the beneficiary of it! That's why i have an attribute "Type" in "Transaction" : Beneficied or Paid transaction :) – Pwyll28 Apr 14 '13 at 21:49

1 Answers1

0

Okay, I think what I'm hearing is that your model looks good. If you want a list of all of the expenses associated with an Event you'll have to go through the guests. The following is pseudocode since I'm not exactly sure on the syntax

NSMutableArray* expenseList; //This will contain all of the expense objects for a given event
   for Guest* guestObject in myEvent.guests
   {
      for Transaction* transactionObject in guestObject.transactions
      {
          [expenseList addObject:transactionObject.expense];
      }
   }
Pinwheeler
  • 1,061
  • 2
  • 13
  • 26
  • I've resolved my problem adding a relation between Event and Expense :) But this code works too ^^ Thanks @Pinwheeler ! – Pwyll28 Apr 16 '13 at 21:20