Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialClair Griffiths
10,158 PointsHelp working out models and relationships for project
I am starting a Campaign Management project in Rails but I'm getting incredibly confused with the models and relationships.
There will be multiple Campaigns (that's the easy part!). Each campaign has a budget which is spent by channel (posters, press, magazines) by week.
So, for example, for Campaign 1, I may choose to spend £100 on Posters in week 1, 2 and 3 and spend £50 on Press in week 1 and 2.
I'm pretty sure I shouldn't be creating a model for Week, but how would I set up the models and relationships between them? I'm utterly lost.
Many thanks in advance.
2 Answers
Tim Knight
28,888 PointsHi Clair,
I've done something similar to this in the past. The way I considered it was that a campaign has a 'spend', basically an amount of money that is spent on a particular media for a campaign.
So your campaign would have a name, probably a start and end date, and maybe a budget. And a campaign has_many :spends
Then you have a spend which belongs_to :campaign
and the spend would have a name or media, a cost, and then you could either have a start and end date on that work just a week. For the week I'd just create a dropdown for something is basically "Week 1" through "Week 4", nothing complex. It's really the spend that has the relationship with the campaign that's the important part.
If you're also tracking the success of the spends you could create a model for lead
or sales
or whatever and that belongs to a spend as well... and the spend would have many sales.
Does that make sense? Just one way to do it.
Andrew Stelmach
12,583 PointsWhat do you want the app to do?
Clair Griffiths
10,158 PointsHi Andrew
Ultimately I'd like to create a series of dynamic charts that would allow me to filter the data based on these criteria. So for example, I would want to look at the weekly spend across all campaigns on Posters, or see how much money I was spending across all Campaigns in week 7. Basically its a central place to house information with the ability to run various reports.
Hope that makes sense, please let me know if you need further info!
Clair Griffiths
10,158 PointsClair Griffiths
10,158 PointsHey Tim
Thanks so much for that! The first bit makes a lot of sense: having a 'spend' that belongs to a campaign and having an attribute within it to say which channel it is using. I'm still a little hazy on the 'week' part of it though.
So lets say that I have a Campaign which has_many spends. My first spend is £100 on 'posters' and my second spend is £50 on press. I'd like to split that £100 spend between 2 weeks ( £50 in week 1 and £50 in week 2). Are you saying that I would create an attribute (like the channel one) for week 1 and another for week 2 and then enter the spend in there? Apologies if I'm being a bit slow or I've misunderstood!
I can see how that may work, I was hoping at some point to be able to automatically create the relevant weeks in a form based on the campaign start and end date which I'm not sure would be possible this way, but I can work around it!
Tim Knight
28,888 PointsTim Knight
28,888 PointsWell I think it depends on what you're going to be doing with "weeks". If you're going to run reports across all things for a week you're week could also be a model attribute that a spend could belong to. If there are going to be a certain set of weeks, you could just hard code a select list and then run queries against the week column on the spent. Does that make sense?
Clair Griffiths
10,158 PointsClair Griffiths
10,158 PointsIt does make sense, thank you! I decided to create a model called weeks and it now makes a lot more sense. Many thanks for your help!