Hi everyone, I just started learning ruby on rails coming from php and mysql worlds. The tutorial are getting really confusing!!! According to this guides.rubyonrails.org/migrations.html if you want to add foreign key to a model it is not possible unless you use SQL format and explicitly tell it where it is. On the other-side, you have this guides.rubyonrails.org/association_basics.html tutorial it is possible by simply telling which field are related. Now which tutorial i am suppose to believe??? Also if the association together does it return the entire order rows or just one item of it. and if i look in a db_migrate file why is there no id field already in the file? Where does it get created? Thanks but its a bit confusing coming from other language. -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On Jul 12, 2012, at 10:27 AM, Jean-Sébastien D. wrote:> Hi everyone, > > I just started learning ruby on rails coming from php and mysql worlds. > The tutorial are getting really confusing!!! According to this > guides.rubyonrails.org/migrations.html if you want to add foreign > key to a model it is not possible unless you use SQL format and > explicitly tell it where it is.I think that''s referring to actual DB-enforced foreign key constraints. ActiveRecord provides a lot of helpful methods in the associations that basically mimc what a traditional fk would do, but at the Ruby level.> > On the other-side, you have this > guides.rubyonrails.org/association_basics.html tutorial it is > possible by simply telling which field are related.I would follow this until you feel some pain that it doesn''t solve. If you find that a real fk is the only way, look at the Foreigner gem, which is an ActiveRecord extension that wraps real DB key constraints.> > Now which tutorial i am suppose to believe??? Also if the association > together does it return the entire order rows or just one item of it. > and if i look in a db_migrate file why is there no id field already in > the file? Where does it get created?Read carefully through the associations guide. The ActiveRecord associations are deep and powerful. Also read through the migrations guide. The id, created_at, and updated_at columns are all "assumed" in any migration, unless you add some flags to suppress them when making the migration.> > Thanks but its a bit confusing coming from other language.But so worth it. I just spent all of yesterday untwisting some PHP I wrote in 2004. Fun? No, not really. Walter> > -- > Posted via ruby-forum.com. > > -- > 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@googlegroups.com. > For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US. >-- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Walter Davis wrote in post #1068445:> On Jul 12, 2012, at 10:27 AM, Jean-Sbastien D. wrote: > >> Hi everyone, >> >> I just started learning ruby on rails coming from php and mysql worlds. >> The tutorial are getting really confusing!!! According to this >> guides.rubyonrails.org/migrations.html if you want to add foreign >> key to a model it is not possible unless you use SQL format and >> explicitly tell it where it is. > > I think that''s referring to actual DB-enforced foreign key constraints. > ActiveRecord provides a lot of helpful methods in the associations that > basically mimc what a traditional fk would do, but at the Ruby level. > >> >> On the other-side, you have this >> guides.rubyonrails.org/association_basics.html tutorial it is >> possible by simply telling which field are related. > > I would follow this until you feel some pain that it doesn''t solve. If > you find that a real fk is the only way, look at the Foreigner gem, > which is an ActiveRecord extension that wraps real DB key constraints. > >> >> Now which tutorial i am suppose to believe??? Also if the association >> together does it return the entire order rows or just one item of it. >> and if i look in a db_migrate file why is there no id field already in >> the file? Where does it get created? > > Read carefully through the associations guide. The ActiveRecord > associations are deep and powerful. Also read through the migrations > guide. The id, created_at, and updated_at columns are all "assumed" in > any migration, unless you add some flags to suppress them when making > the migration. > >> >> Thanks but its a bit confusing coming from other language. > > But so worth it. I just spent all of yesterday untwisting some PHP I > wrote in 2004. Fun? No, not really. > > WalterThanks I appreciate! I have one last questions!! Because i started recently and not on a production server for what i am building. I created rought models with bunch of fields, and did rake db:migrate. So now they are created but I want to take those field out. How should I proceed?? I would like to go into the db/folder find the model modify it to what i needs exactly then was hoping to do rake db:migrate to refresh with the newest options, this doesnt seem to work. What would be my other option, and there are over 50 model so i already try rake db:reset but that didn''t do anything other than resetting my data. -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On Jul 12, 2012, at 10:58 AM, Jean-Sébastien D. wrote:> Walter Davis wrote in post #1068445: >> On Jul 12, 2012, at 10:27 AM, Jean-Sbastien D. wrote: >> >>> Hi everyone, >>> >>> I just started learning ruby on rails coming from php and mysql worlds. >>> The tutorial are getting really confusing!!! According to this >>> guides.rubyonrails.org/migrations.html if you want to add foreign >>> key to a model it is not possible unless you use SQL format and >>> explicitly tell it where it is. >> >> I think that''s referring to actual DB-enforced foreign key constraints. >> ActiveRecord provides a lot of helpful methods in the associations that >> basically mimc what a traditional fk would do, but at the Ruby level. >> >>> >>> On the other-side, you have this >>> guides.rubyonrails.org/association_basics.html tutorial it is >>> possible by simply telling which field are related. >> >> I would follow this until you feel some pain that it doesn''t solve. If >> you find that a real fk is the only way, look at the Foreigner gem, >> which is an ActiveRecord extension that wraps real DB key constraints. >> >>> >>> Now which tutorial i am suppose to believe??? Also if the association >>> together does it return the entire order rows or just one item of it. >>> and if i look in a db_migrate file why is there no id field already in >>> the file? Where does it get created? >> >> Read carefully through the associations guide. The ActiveRecord >> associations are deep and powerful. Also read through the migrations >> guide. The id, created_at, and updated_at columns are all "assumed" in >> any migration, unless you add some flags to suppress them when making >> the migration. >> >>> >>> Thanks but its a bit confusing coming from other language. >> >> But so worth it. I just spent all of yesterday untwisting some PHP I >> wrote in 2004. Fun? No, not really. >> >> Walter > > > Thanks I appreciate! > > I have one last questions!! > > Because i started recently and not on a production server for what i am > building. I created rought models with bunch of fields, and did rake > db:migrate. So now they are created but I want to take those field out. > How should I proceed?? I would like to go into the db/folder find the > model modify it to what i needs exactly then was hoping to do rake > db:migrate to refresh with the newest options, this doesnt seem to work. > What would be my other option, and there are over 50 model so i already > try rake db:reset but that didn''t do anything other than resetting my > data.If you read through the migrations guide, you will learn about rake db:rollback, which will step backward through your migrations. You can then hand-edit the migrations, delete the ones that have rolled back and generate new ones, or some combination of those. Just don''t remove an already-run migration without rolling it back first. Walter> > -- > Posted via ruby-forum.com. > > -- > 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@googlegroups.com. > For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US. >-- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Walter Davis wrote in post #1068451:> On Jul 12, 2012, at 10:58 AM, Jean-Sbastien D. wrote: > >>> >>> you find that a real fk is the only way, look at the Foreigner gem, >>> guide. The id, created_at, and updated_at columns are all "assumed" in >> >> db:migrate to refresh with the newest options, this doesnt seem to work. >> What would be my other option, and there are over 50 model so i already >> try rake db:reset but that didn''t do anything other than resetting my >> data. > > If you read through the migrations guide, you will learn about rake > db:rollback, which will step backward through your migrations. You can > then hand-edit the migrations, delete the ones that have rolled back and > generate new ones, or some combination of those. Just don''t remove an > already-run migration without rolling it back first. > > WalterIs there a way for me to select one specifically something like this rake db:rollback YYYYMMDDHHMMSS_model.rb -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 12 July 2012 16:06, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> > On Jul 12, 2012, at 10:58 AM, Jean-Sébastien D. wrote: > >> Walter Davis wrote in post #1068445: >>> On Jul 12, 2012, at 10:27 AM, Jean-Sbastien D. wrote: >>> >>>> Hi everyone, >>>> >>>> I just started learning ruby on rails coming from php and mysql worlds. >>>> The tutorial are getting really confusing!!! According to this >>>> guides.rubyonrails.org/migrations.html if you want to add foreign >>>> key to a model it is not possible unless you use SQL format and >>>> explicitly tell it where it is. >>> >>> I think that''s referring to actual DB-enforced foreign key constraints. >>> ActiveRecord provides a lot of helpful methods in the associations that >>> basically mimc what a traditional fk would do, but at the Ruby level. >>> >>>> >>>> On the other-side, you have this >>>> guides.rubyonrails.org/association_basics.html tutorial it is >>>> possible by simply telling which field are related. >>> >>> I would follow this until you feel some pain that it doesn''t solve. If >>> you find that a real fk is the only way, look at the Foreigner gem, >>> which is an ActiveRecord extension that wraps real DB key constraints. >>> >>>> >>>> Now which tutorial i am suppose to believe??? Also if the association >>>> together does it return the entire order rows or just one item of it. >>>> and if i look in a db_migrate file why is there no id field already in >>>> the file? Where does it get created? >>> >>> Read carefully through the associations guide. The ActiveRecord >>> associations are deep and powerful. Also read through the migrations >>> guide. The id, created_at, and updated_at columns are all "assumed" in >>> any migration, unless you add some flags to suppress them when making >>> the migration. >>> >>>> >>>> Thanks but its a bit confusing coming from other language. >>> >>> But so worth it. I just spent all of yesterday untwisting some PHP I >>> wrote in 2004. Fun? No, not really. >>> >>> Walter >> >> >> Thanks I appreciate! >> >> I have one last questions!! >> >> Because i started recently and not on a production server for what i am >> building. I created rought models with bunch of fields, and did rake >> db:migrate. So now they are created but I want to take those field out. >> How should I proceed?? I would like to go into the db/folder find the >> model modify it to what i needs exactly then was hoping to do rake >> db:migrate to refresh with the newest options, this doesnt seem to work. >> What would be my other option, and there are over 50 model so i already >> try rake db:reset but that didn''t do anything other than resetting my >> data. > > If you read through the migrations guide, you will learn about rake db:rollback, which will step backward through your migrations. You can then hand-edit the migrations, delete the ones that have rolled back and generate new ones, or some combination of those. Just don''t remove an already-run migration without rolling it back first.That can be done but it is often better to write a new migration to remove the stuff you have decided you did not need after all. Rollback is fine if you make a migration, run it, but then realise that it was a bad idea and want to go back to the previous one and remove the migration. For any more complex situation I would advise writing a new migration to undo the previous one instead. Otherwise it is easy to get confused about the state of the database. Also, as well as looking through the guides I suggest working right through a tutorial such as railstutorial.org, which is free to use online, to get the basics of Rails. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On Jul 12, 2012, at 11:18 AM, Jean-Sébastien D. wrote:>> If you read through the migrations guide, you will learn about rake >> db:rollback, which will step backward through your migrations. You can >> then hand-edit the migrations, delete the ones that have rolled back and >> generate new ones, or some combination of those. Just don''t remove an >> already-run migration without rolling it back first. >> >> Walter > > Is there a way for me to select one specifically something like this > > rake db:rollback YYYYMMDDHHMMSS_model.rbI don''t know specifically -- what do the guides say? I''ve only ever stepped back one or two at a time, made my adjustments, then run rake db:migrate again to roll back up to the current stage. Walter -- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Walter Davis wrote in post #1068458:> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: > >> rake db:rollback YYYYMMDDHHMMSS_model.rb > I don''t know specifically -- what do the guides say? I''ve only ever > stepped back one or two at a time, made my adjustments, then run rake > db:migrate again to roll back up to the current stage. > > WalterThanks I appreciate, i find it weird that you must make a new migration everytime you made a mistake, its seem to be a lot of overhead in compilation time. Maybe something that future rails should invest. Who knows I just started learning ruby. Thanks -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
Jean-Sébastien D. wrote in post #1068459:> Walter Davis wrote in post #1068458: >> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: >> >>> rake db:rollback YYYYMMDDHHMMSS_model.rb >> I don''t know specifically -- what do the guides say? I''ve only ever >> stepped back one or two at a time, made my adjustments, then run rake >> db:migrate again to roll back up to the current stage. >> >> Walter > > Thanks I appreciate, i find it weird that you must make a new migration > everytime you made a mistake, its seem to be a lot of overhead in > compilation time. Maybe something that future rails should invest. Who > knows I just started learning ruby. > > ThanksOne more questions.. If i have two tables it should be declared has follow to have my foreign key CUSTOMER ORDER first customer_id last pay_to ... ... Correct then in the model i should specify the relation ship correct? -- Posted via ruby-forum.com. -- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On Jul 12, 2012, at 12:30 PM, Jean-Sébastien D. wrote:> Walter Davis wrote in post #1068458: >> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: >> >>> rake db:rollback YYYYMMDDHHMMSS_model.rb >> I don''t know specifically -- what do the guides say? I''ve only ever >> stepped back one or two at a time, made my adjustments, then run rake >> db:migrate again to roll back up to the current stage. >> >> Walter > > Thanks I appreciate, i find it weird that you must make a new migration > everytime you made a mistake, its seem to be a lot of overhead in > compilation time. Maybe something that future rails should invest. Who > knows I just started learning ruby. >The migrations are typically only run during development, and then you can install from the schema (which maintains a "current state" of the database at all times) when you get to production. Migrations are a great way to build an application organically, because you can roll them back and undo a spike you tried and didn''t like. Use them like Git for your database. Walter> Thanks > > -- > Posted via ruby-forum.com. > > -- > 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@googlegroups.com. > For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US. >-- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On 12 July 2012 17:30, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Walter Davis wrote in post #1068458: >> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: >> >>> rake db:rollback YYYYMMDDHHMMSS_model.rb >> I don''t know specifically -- what do the guides say? I''ve only ever >> stepped back one or two at a time, made my adjustments, then run rake >> db:migrate again to roll back up to the current stage. >> >> Walter > > Thanks I appreciate, i find it weird that you must make a new migration > everytime you made a mistake, its seem to be a lot of overhead in > compilation time. Maybe something that future rails should invest. Who > knows I just started learning ruby.What compilation time? A migration is only loaded and run when you ask for it. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On 12 July 2012 17:37, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Jean-Sébastien D. wrote in post #1068459: >> Walter Davis wrote in post #1068458: >>> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: >>> >>>> rake db:rollback YYYYMMDDHHMMSS_model.rb >>> I don''t know specifically -- what do the guides say? I''ve only ever >>> stepped back one or two at a time, made my adjustments, then run rake >>> db:migrate again to roll back up to the current stage. >>> >>> Walter >> >> Thanks I appreciate, i find it weird that you must make a new migration >> everytime you made a mistake, its seem to be a lot of overhead in >> compilation time. Maybe something that future rails should invest. Who >> knows I just started learning ruby. >> >> Thanks > > One more questions.. > If i have two tables it should be declared has follow to have my foreign > key > CUSTOMER ORDER > first customer_id > last pay_to > ... ... > > Correct then in the model i should specify the relation ship correct?Can you explain the above again, I don''t understand what you are trying to achieve. Also it is best to talk first about models and relationships, (has_many, belongs_to and so on) then the table requirements will follow from that. So first tell us what the models are and what the relationships are. Colin> > -- > Posted via ruby-forum.com. > > -- > 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@googlegroups.com. > For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US. >-- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Colin Law wrote in post #1068465:> On 12 July 2012 17:37, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >> CUSTOMER ORDER >> first customer_id >> last pay_to >> ... ... >> >> Correct then in the model i should specify the relation ship correct? > > Can you explain the above again, I don''t understand what you are > trying to achieve. Also it is best to talk first about models and > relationships, (has_many, belongs_to and so on) then the table > requirements will follow from that. > > So first tell us what the models are and what the relationships are. > > ColinWell i am from MySQL world. I am use to a database has follow CUSTOMER ORDER customerID orderID firstName customerID lastName price password proceededAt emails In MySQL you would have has follow: PK customerID, orderID, FK order(customerID) to customer(customerID) In Rails if I understood I create has follow CUSTOMER ORDER first_name price last_name proceed_at password emails Now in models I would have to say Customer belongs to order Order has customer Now my main questions I understand I dont define customer_id and order_id in customer and order table because its already assume to have an id key when created. But in ORDER model should I define customer_id:integer and in model say ORder customer_id: has customer. To let it know that this field is actually a foreign key? -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 12 July 2012 17:56, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1068465: >> On 12 July 2012 17:37, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> >>> CUSTOMER ORDER >>> first customer_id >>> last pay_to >>> ... ... >>> >>> Correct then in the model i should specify the relation ship correct? >> >> Can you explain the above again, I don''t understand what you are >> trying to achieve. Also it is best to talk first about models and >> relationships, (has_many, belongs_to and so on) then the table >> requirements will follow from that. >> >> So first tell us what the models are and what the relationships are. >> >> Colin > > Well i am from MySQL world. I am use to a database has follow > > CUSTOMER ORDER > customerID orderID > firstName customerID > lastName price > password proceededAt > emails > > In MySQL you would have has follow: PK customerID, orderID, FK > order(customerID) to customer(customerID) > > In Rails if I understood I create has follow > > CUSTOMER ORDER > first_name price > last_name proceed_at > password > emails > > Now in models I would have to say > > Customer belongs to order > Order has customerI think that should be customer has_many orders and order belongs_to customer. The words make some reasonable sense in english.> > Now my main questions I understand I dont define customer_id and > order_id in customer and order table because its already assume to have > an id key when created. But in ORDER model should I define > customer_id:integer and in model say > ORder customer_id: has customer. To let it know that this field is > actually a foreign key?Since order belongs_to customer then the orders table (note the plural name for the table) should have a customer_id column. You don''t need to tell rails that it is a foreign key, it will know that from the model relationships. To specify it in the migration for orders you can say (as is mentioned in the migrations guide). t.references :customer or t.integer :customer_id As I think I said previously if you work right through some tutorials all this should become clear. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On Thursday, July 12, 2012 12:37:33 PM UTC-4, Walter Lee Davis wrote:> > > On Jul 12, 2012, at 12:30 PM, Jean-Sébastien D. wrote: > > > Walter Davis wrote in post #1068458: > >> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: > >> > >>> rake db:rollback YYYYMMDDHHMMSS_model.rb > >> I don''t know specifically -- what do the guides say? I''ve only ever > >> stepped back one or two at a time, made my adjustments, then run rake > >> db:migrate again to roll back up to the current stage. > >> > >> Walter > > > > Thanks I appreciate, i find it weird that you must make a new migration > > everytime you made a mistake, its seem to be a lot of overhead in > > compilation time. Maybe something that future rails should invest. Who > > knows I just started learning ruby. > > > > The migrations are typically only run during development, and then you can > install from the schema (which maintains a "current state" of the database > at all times)This is not true. Lets say you have a working system, being used by thousands of users. The database has enough data that a backup/restore takes half a day. Then you need to add a new feature that requires 3 new tables, and new columns on an existing table. How are you supposed to do this *without* running a migration against the production system? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit groups.google.com/d/msg/rubyonrails-talk/-/vsEgGxckAXwJ. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On 12 July 2012 18:38, Andy Chambers <achambers.home-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thursday, July 12, 2012 12:37:33 PM UTC-4, Walter Lee Davis wrote: >> >> >> On Jul 12, 2012, at 12:30 PM, Jean-Sébastien D. wrote: >> >> > Walter Davis wrote in post #1068458: >> >> On Jul 12, 2012, at 11:18 AM, Jean-Sbastien D. wrote: >> >> >> >>> rake db:rollback YYYYMMDDHHMMSS_model.rb >> >> I don''t know specifically -- what do the guides say? I''ve only ever >> >> stepped back one or two at a time, made my adjustments, then run rake >> >> db:migrate again to roll back up to the current stage. >> >> >> >> Walter >> > >> > Thanks I appreciate, i find it weird that you must make a new migration >> > everytime you made a mistake, its seem to be a lot of overhead in >> > compilation time. Maybe something that future rails should invest. Who >> > knows I just started learning ruby. >> > >> >> The migrations are typically only run during development, and then you can >> install from the schema (which maintains a "current state" of the database >> at all times) > > > This is not true. Lets say you have a working system, being used by > thousands of users. The database has enough data that a backup/restore > takes half a day. Then you need to add a new feature that requires 3 new > tables, and new columns on an existing table. How are you supposed to do > this *without* running a migration against the production system?I suspect Walter meant "during the development phase" rather than "in development mode". Migrations are applied to the production database during development. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Colin Law wrote in post #1068473:> On 12 July 2012 17:56, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> Can you explain the above again, I don''t understand what you are >> CUSTOMER ORDER >> >> CUSTOMER ORDER >> first_name price >> last_name proceed_at >> password >> emails >> >> Now in models I would have to say >> >> Customer belongs to order >> Order has customer > > I think that should be customer has_many orders and order belongs_to > customer. The words make some reasonable sense in english. > >> >> Now my main questions I understand I dont define customer_id and >> order_id in customer and order table because its already assume to have >> an id key when created. But in ORDER model should I define >> customer_id:integer and in model say >> ORder customer_id: has customer. To let it know that this field is >> actually a foreign key? > > Since order belongs_to customer then the orders table (note the plural > name for the table) should have a customer_id column. You don''t need > to tell rails that it is a foreign key, it will know that from the > model relationships. To specify it in the migration for orders you > can say (as is mentioned in the migrations guide). > > t.references :customer > or > t.integer :customer_id > > As I think I said previously if you work right through some tutorials > all this should become clear. > > ColinSorry here a question in term of modeling!! BTW thanks I am learning a lots with your comments But I just want to make sure I get the association concept understood well. I place a question few days ago on this links railsforum.com/viewtopic.php?pid=153916#p153916 but don''t seem to have quick Answer. I just wanna make sure I understand the concept of association compared to php -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 02:23, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1068473: >> On 12 July 2012 17:56, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> Can you explain the above again, I don''t understand what you are >>> CUSTOMER ORDER >>> >>> CUSTOMER ORDER >>> first_name price >>> last_name proceed_at >>> password >>> emails >>> >>> Now in models I would have to say >>> >>> Customer belongs to order >>> Order has customer >> >> I think that should be customer has_many orders and order belongs_to >> customer. The words make some reasonable sense in english. >> >>> >>> Now my main questions I understand I dont define customer_id and >>> order_id in customer and order table because its already assume to have >>> an id key when created. But in ORDER model should I define >>> customer_id:integer and in model say >>> ORder customer_id: has customer. To let it know that this field is >>> actually a foreign key? >> >> Since order belongs_to customer then the orders table (note the plural >> name for the table) should have a customer_id column. You don''t need >> to tell rails that it is a foreign key, it will know that from the >> model relationships. To specify it in the migration for orders you >> can say (as is mentioned in the migrations guide). >> >> t.references :customer >> or >> t.integer :customer_id >> >> As I think I said previously if you work right through some tutorials >> all this should become clear. >> >> Colin > > Sorry here a question in term of modeling!! BTW thanks I am learning a > lots with your comments > > But I just want to make sure I get the association concept understood > well. I place a question few days ago on this links > railsforum.com/viewtopic.php?pid=153916#p153916 but don''t seem to > have quick Answer. I just wanna make sure I understand the concept of > association compared to phpIt is no good just posting a link to a thread that appears to have already been answered. If you have a specific still unanswered question then post it here. However as I have said twice before you really should work through some tutorials to get the basics rather than asking such questions here. Once you have done that the answers will mostly become obvious to you. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Colin Law wrote in post #1068538:> On 13 July 2012 02:23, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> >>>> order_id in customer and order table because its already assume to have >>> >> lots with your comments >> >> But I just want to make sure I get the association concept understood >> well. I place a question few days ago on this links >> railsforum.com/viewtopic.php?pid=153916#p153916 but don''t seem to >> have quick Answer. I just wanna make sure I understand the concept of >> association compared to php > > It is no good just posting a link to a thread that appears to have > already been answered. If you have a specific still unanswered > question then post it here. However as I have said twice before you > really should work through some tutorials to get the basics rather > than asking such questions here. Once you have done that the answers > will mostly become obvious to you. > > ColinOh Thanks didn''t ice someone already posted an answer. Well these are all my questions, I thanks everyone!! -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
Here a final questions, not sure if you may know. I installed activeadmin has a gem and it allow me to manage any customer, interest and a manager to control when this one is expired or so It has the following associations class Client < ActiveRecord::Base has_many :music_interest_managers has_many :music_interests, through => :music_interest_managers end class MusicInterest < ActiveRecord::Base has_many :music_interest_managers has_many :clients, through => :music_interest_managers end class MusicInterestManager < ActiveRecord::Base belongs_to :music_interests belongs_to :client end But when installing a resources for MusicInterestManager I get the following error! Showing /home/jean/.rvm/gems/ruby-1.9.3-p194/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb where line #1 raised: uninitialized constant ActivitiesManager::Customers Extracted source (around line #1): 1: render renderer_for(:index) Rails.root: /home/jean/rail/wyw Application Trace | Framework Trace | Full Trace Maybe i should ask the activeadmin forum, but i just wanted to see if you guys knew anything about it!!Thanks! -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 14:58, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Here a final questions, not sure if you may know. I installed > activeadmin has a gem and it allow me to manage any customer, interest > and a manager to control when this one is expired or so > > It has the following associations > > class Client < ActiveRecord::Base > has_many :music_interest_managers > has_many :music_interests, through => :music_interest_managers > end > class MusicInterest < ActiveRecord::Base > has_many :music_interest_managers > has_many :clients, through => :music_interest_managers > end > class MusicInterestManager < ActiveRecord::Base > belongs_to :music_interestsHow many music_interests does it belong to. The fact that you have used the plural suggests it belongs to several, but that does not seem likely.> belongs_to :client > end > > But when installing a resources for MusicInterestManager I get the > following error! > > Showing > /home/jean/.rvm/gems/ruby-1.9.3-p194/gems/activeadmin-0.4.4/app/views/active_admin/resource/index.html.arb > where line #1 raised: > > uninitialized constant ActivitiesManager::CustomersActivitiesManager and Customers? Where did they come from? How are you getting on with the tutorials? 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
On Jul 13, 2012, at 9:58 AM, Jean-Sébastien D. wrote:> Here a final questions, not sure if you may know. I installed > activeadmin has a gem and it allow me to manage any customer, interest > and a manager to control when this one is expired or soJust a side-note here. I really STRONGLY recommend that you don''t jump into an "easy" admin tool like this until you have worked out the very basic way that Rails works. These toolkits introduce a second level of abstraction over Rails, and while they can jump-start a site and give you 90% of what you need right out of the box, they also keep you from learning how the system works, which will rear up and bite you later. Further, they can often make that last 10% nearly impossible to attain, and complicate the process of learning even more. Just my two pfennigs here. Walter -- 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Colin Law wrote in post #1068577:> On 13 July 2012 14:58, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> class MusicInterest < ActiveRecord::Base >> has_many :music_interest_managers >> has_many :clients, through => :music_interest_managers >> end >> class MusicInterestManager < ActiveRecord::Base >> belongs_to :music_interests > > How many music_interests does it belong to. The fact that you have > used the plural suggests it belongs to several, but that does not seem > likely. > >> uninitialized constant ActivitiesManager::Customers > ActivitiesManager and Customers? Where did they come from? > > How are you getting on with the tutorials? > > ColinSorry the example customer and music_interest_manager was just an example, the customer and activities_managers is my actual names. Here the real test lookup class ActivitiesManager < ActiveRecord::Base belongs_to :customers belongs_to :activities class Activity < ActiveRecord::Base has_many :activities_managers has_many :customers, :through => :activities_managers class Customer < ActiveRecord::Base has_many :activities_managers has_many :activities, :through => :activities_managers I am just using this tools for administrative backend feature not the front end. I am just curious the way I wrote it down to see if its correct or if something else is wrong with my style of writing ruby. -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 15:35, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1068577: >> On 13 July 2012 14:58, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> class MusicInterest < ActiveRecord::Base >>> has_many :music_interest_managers >>> has_many :clients, through => :music_interest_managers >>> end >>> class MusicInterestManager < ActiveRecord::Base >>> belongs_to :music_interests >> >> How many music_interests does it belong to. The fact that you have >> used the plural suggests it belongs to several, but that does not seem >> likely. >> >>> uninitialized constant ActivitiesManager::Customers >> ActivitiesManager and Customers? Where did they come from? >> >> How are you getting on with the tutorials? >> >> Colin > > Sorry the example customer and music_interest_manager was just an > example, the customer and activities_managers is my actual names. Here > the real test lookup > > class ActivitiesManager < ActiveRecord::Base > belongs_to :customersIf you followed my advise and worked through some tutorials you might not make so many silly mistakes. How many customers does an ActivitiesManager belong to? The fact that you have said belongs_to customers suggests that it belongs to more than one customer, which is unlikely.> belongs_to :activitiesDitto 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Colin Law wrote in post #1068584:> On 13 July 2012 15:35, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> used the plural suggests it belongs to several, but that does not seem >> example, the customer and activities_managers is my actual names. Here >> the real test lookup >> >> class ActivitiesManager < ActiveRecord::Base >> belongs_to :customers > > If you followed my advise and worked through some tutorials you might > not make so many silly mistakes. How many customers does an > ActivitiesManager belong to? The fact that you have said belongs_to > customers suggests that it belongs to more than one customer, which is > unlikely. > >> belongs_to :activities > > Ditto > > ColinIt his has follow Customer Manager Activity John John 1 2012-01-05 1 Soccer Josh John 3 2012-01-07 2 Hockey Josh 2 2012-01-05 3 Footbal The purpose is to keep track of everything So there the model Customer has_many Manager Manager belongs to Customer Manager belongs to Activity Activity has_one Manager Does this make sense? -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 15:49, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #1068584: >> On 13 July 2012 15:35, Jean-Sbastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> used the plural suggests it belongs to several, but that does not seem >>> example, the customer and activities_managers is my actual names. Here >>> the real test lookup >>> >>> class ActivitiesManager < ActiveRecord::Base >>> belongs_to :customers >> >> If you followed my advise and worked through some tutorials you might >> not make so many silly mistakes. How many customers does an >> ActivitiesManager belong to? The fact that you have said belongs_to >> customers suggests that it belongs to more than one customer, which is >> unlikely. >> >>> belongs_to :activities >> >> Ditto >> >> Colin > > It his has follow > > Customer Manager Activity > John John 1 2012-01-05 1 Soccer > Josh John 3 2012-01-07 2 Hockey > Josh 2 2012-01-05 3 Footbal > > The purpose is to keep track of everything > > So there the model > Customer has_many Manager > Manager belongs to Customer > Manager belongs to Activity > Activity has_one Manager > > Does this make sense?How are you getting on with the tutorials? 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
Thanks it make more sense!!! So my structure should be as follow: class ActivitiesManager < ActiveRecord::Base belongs_to :customers belongs_to :activities class Activity < ActiveRecord::Base has_one :activities_manager class Customer < ActiveRecord::Base has_many :activities_managers has_many :activities, :through => :activities_managers I also read the entire book 3 time in the last 2 weeks ruby.railstutorial.org/chapters -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 16:13, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks it make more sense!!! > > So my structure should be as follow: > class ActivitiesManager < ActiveRecord::Base > belongs_to :customers > belongs_to :activitiesPlease answer the question - how many customers does an activitiesmanager belong to?> class Activity < ActiveRecord::Base > has_one :activities_manager > class Customer < ActiveRecord::Base > has_many :activities_managers > has_many :activities, :through => :activities_managers > > I also read the entire book 3 time in the last 2 weeks > ruby.railstutorial.org/chaptersReading it is not enough. Work right through it, typing and running the code on your PC, make sure you understand every single line of code. Do all the exercises. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.
> Please answer the question - how many customers does an > activitiesmanager belong to?An activity manager can have multiple customer and repeat many time the same customer. but an activity manager can only have one to one activity So it should be has follow class ActivitiesManager < ActiveRecord::Base belongs_to :customers belongs_to :activity class Activity < ActiveRecord::Base has_one :activities_manager class Customer < ActiveRecord::Base has_many :activities_managers has_many :activities, :through => :activities_managers> Reading it is not enough. Work right through it, typing and running > the code on your PC, make sure you understand every single line of > code. Do all the exercises.In term of exercise i have done up to chapter 9 so far -- Posted via ruby-forum.com. -- 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 groups.google.com/group/rubyonrails-talk?hl=en-US.
On 13 July 2012 16:27, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:>> Please answer the question - how many customers does an >> activitiesmanager belong to? > > An activity manager can have multiple customer and repeat many time the > same customer. but an activity manager can only have one to one activity > > So it should be has follow > class ActivitiesManager < ActiveRecord::Base > belongs_to :customersThe belongs_to association implies a one to many association, so an activities manager can only have one customer as you have declared it here, and belongs_to :customers is not valid. It must be belongs_to :customer.> belongs_to :activity > class Activity < ActiveRecord::Base > has_one :activities_manager > class Customer < ActiveRecord::Base > has_many :activities_managers > has_many :activities, :through => :activities_managers > >> Reading it is not enough. Work right through it, typing and running >> the code on your PC, make sure you understand every single line of >> code. Do all the exercises. > > In term of exercise i have done up to chapter 9 so farThe has_many, belongs_to association is dealt with in Chapter 10. I suggest, once again, that you finish the tutorial before continuing with your application. 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@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en-US.