Hi! I have a uncommon (I think problem). In my RoR app there''re 3 models: - Transaction (date:datetime, worker_id:integer, successful:boolean) - Sale (amount:integer, transaction_id:integer, medicine_id:integer) - Medicine (...) Transaction is some kind of bill, is like container of Sales with one attached Medicine, so it looks like that: Transaction ---[0..*]---> Sale ---[1..1]---> Medicine or like a tree: Transaction -> Sale -> Medicine -> Sale -> Medicine How to make relations? I tried to use these ones: Transaction: has_many :sales Sale: belongs_to :transactions has_one :medicine So now the problems starts, because even if I create new transaction and then try to make sale, nothing happens :/ It says "Successfuly created new sale", but it doesn''t show on listing. Could anyone explain how to connect these models through relations? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Apr 2008, at 19:22, Pawe? K wrote:> > Hi! > > I have a uncommon (I think problem). In my RoR app there''re 3 models: > - Transaction (date:datetime, worker_id:integer, successful:boolean) > - Sale (amount:integer, transaction_id:integer, medicine_id:integer) > - Medicine (...) > > Transaction is some kind of bill, is like container of Sales with one > attached Medicine, so it looks like that: > > Transaction ---[0..*]---> Sale ---[1..1]---> MedicineDon''t call your model transaction. If you do then the methods that a generated to access your transaction will conflict with the built in methods for handling database transactions (and so bad stuff will happen). Fred> or like a tree: > > Transaction > -> Sale -> Medicine > -> Sale -> Medicine > > How to make relations? I tried to use these ones: > > Transaction: > has_many :sales > > Sale: > belongs_to :transactions > has_one :medicine > > So now the problems starts, because even if I create new transaction > and then try to make sale, nothing happens :/ It says "Successfuly > created new sale", but it doesn''t show on listing. > > Could anyone explain how to connect these models through relations? > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Oh, thaty''s funny, but I did the same with "Transaction" changed to "Bill" and IT WORKS! :) (at least for a moment ;D) Thank you very much :) Probably you have a tip for naming convention in Rails? At this moment I know, there can''t be "Test", "Transaction" etc. model name :/ Should I use preffixes, like "myTransaction"? :D On 27 Kwi, 20:25, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 27 Apr 2008, at 19:22, Pawe? K wrote: > > > > > Hi! > > > I have a uncommon (I think problem). In my RoR app there''re 3 models: > > - Transaction (date:datetime, worker_id:integer, successful:boolean) > > - Sale (amount:integer, transaction_id:integer, medicine_id:integer) > > - Medicine (...) > > > Transaction is some kind of bill, is like container of Sales with one > > attached Medicine, so it looks like that: > > > Transaction ---[0..*]---> Sale ---[1..1]---> Medicine > > Don''t call your model transaction. If you do then the methods that a > generated to access your transaction will conflict with the built in > methods for handling database transactions (and so bad stuff will > happen). > > Fred > > > or like a tree: > > > Transaction > > -> Sale -> Medicine > > -> Sale -> Medicine > > > How to make relations? I tried to use these ones: > > > Transaction: > > has_many :sales > > > Sale: > > belongs_to :transactions > > has_one :medicine > > > So now the problems starts, because even if I create new transaction > > and then try to make sale, nothing happens :/ It says "Successfuly > > created new sale", but it doesn''t show on listing. > > > Could anyone explain how to connect these models through relations?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
There are probably lots of names to avoid. To make sure, I''d search the Rails Brain API here: http://www.railsbrain.com/api/rails-2.0.2/doc/index.html If your proposed name (such as "transaction") turns up a result, there could be a conflict...somewhere. -Kyle On Apr 27, 2:14 pm, Paweł K <komr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh, thaty''s funny, but I did the same with "Transaction" changed to > "Bill" and IT WORKS! :) (at least for a moment ;D) > Thank you very much :) Probably you have a tip for naming convention > in Rails? At this moment I know, there can''t be "Test", "Transaction" > etc. model name :/ Should I use preffixes, like "myTransaction"? :D > > On 27 Kwi, 20:25, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 27 Apr 2008, at 19:22, Pawe? K wrote: > > > > Hi! > > > > I have a uncommon (I think problem). In my RoR app there''re 3 models: > > > - Transaction (date:datetime, worker_id:integer, successful:boolean) > > > - Sale (amount:integer, transaction_id:integer, medicine_id:integer) > > > - Medicine (...) > > > > Transaction is some kind of bill, is like container of Sales with one > > > attached Medicine, so it looks like that: > > > > Transaction ---[0..*]---> Sale ---[1..1]---> Medicine > > > Don''t call your model transaction. If you do then the methods that a > > generated to access your transaction will conflict with the built in > > methods for handling database transactions (and so bad stuff will > > happen). > > > Fred > > > > or like a tree: > > > > Transaction > > > -> Sale -> Medicine > > > -> Sale -> Medicine > > > > How to make relations? I tried to use these ones: > > > > Transaction: > > > has_many :sales > > > > Sale: > > > belongs_to :transactions > > > has_one :medicine > > > > So now the problems starts, because even if I create new transaction > > > and then try to make sale, nothing happens :/ It says "Successfuly > > > created new sale", but it doesn''t show on listing. > > > > Could anyone explain how to connect these models through relations?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---