Bob Smith
2010-Feb-28 20:36 UTC
Wondering about combining has_one and has_many in one application
I am writing an app for a foodbank. The edit screen uses a database called visit with fields of household_id, month, year, monthly, and weekly. Household_id is a link to another database with family records, month and year are for the date of this record, monthly is for a monthly visit, and weekly is for a weekly fruit and bread visit. In the edit screen the Household database has a has_one relationship with Visit, so it only finds 1 record and asks about attendance this month. The problem comes when I try to make a report using has_many. The report shows attendance for the calendar year. I''m sure there is a way to do this with Rails, but I have no idea, so please help.. Bob -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Mar-01 09:07 UTC
Re: Wondering about combining has_one and has_many in one application
On 28 February 2010 20:36, Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am writing an app for a foodbank. The edit screen uses a database > called visit with fields of household_id, month, year, monthly, and > weekly. Household_id is a link to another database with family > records, month and year are for the date of this record, monthly is > for a monthly visit, and weekly is for a weekly fruit and bread visit. > In the edit screen the Household database has a has_one relationship > with Visit, so it only finds 1 record and asks about attendance this > month. The problem comes when I try to make a report using has_many. > The report shows attendance for the calendar year.Relationships have nothing to do with the views you choose to display, but reflect the fundamental relationships of the real-world objects that you are mapping using the database. Think first about these models and their relationships and then build the views you want on top of that. So for example if Household has_many Visits then you may choose to only show one or ones occurring in a particular week, but that does not change the relationship itself. Also it is unusual to use more than one database, or did you mean tables? I do not know how much experience you have with Rails but if that is not a lot you may like to work through some of the guides at http://guides.rubyonrails.org. There is one on ActiveRecord Relationships which may help. Also check out the others. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.