On Jan 20, 2014, at 9:43 AM, Takashi Nakagawa wrote:
> Hi walter, thanks for answering question.
>
> I've read about polymorphic relationships and I've tried it before, but in my case, I should use database which is already used in other project and I make new rails app with the database. so I can' t change database structure easily.
Okay, well there are ways to change Rails' "opinionated" conventions about table naming and model naming. Have a look at the Rails Guides, I don't have time to look it up for you, but I know it's in there.
The only reason I can think of to not do what I recommend here is if you really really actually need some particular database feature to actually make your application work. Rails is mightily database-agnostic, but only if you don't need those features. If you do, then you really will find yourself fighting the conventions of the framework every step of the way.
What I recommend you do is clear off a section of whiteboard and write up a concordance between your existing table names and the models you want to create. So if you have a model named Person, which would want its table to be named people, yet your DBA insisted on naming that one ApplicationUsers or whatever, just draw a big circle and put both names in it. Continue until the *logical* structure of your Rails app is mapped out according to what you want to call your object (which drives the URL structure among other things).
Build your app using a different database -- maybe just a SQLite db -- with all of the tables named the way Rails expects them to be, for speed and flexibility (use migrations). Be sure to write your tests, and get things working the way you want the app to look. Then go back to your whiteboard, and your model files, and add the line of code that re-defines the table name (and primary key, if it isn't named id, or foreign key, if it isn't named singular_underscored_model_name_id) for each of your relationships. Change the database over, and see if it still works. Test and patch until it does.
Walter
>
> 2014年1月17日金曜日 23時25分24秒 UTC+9 Walter Lee Davis:
> Have you read anything about polymorphic relationships yet? That's a good place to start. Rails Guides, ActiveRecord Relations, read the whole page, but pay attention to the section on Polymorphism.
>
> Walter
>
> On Jan 17, 2014, at 4:55 AM, Takashi Nakagawa wrote:
>
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> > To post to this group, send email to rubyonra...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ecc2d9dd-fb18-4248-a50c-4fa9c36721b1%40googlegroups.com.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6e224b17-820d-451e-be23-96b70cbeabf6%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/37EAC3A5-073A-41CA-933A-C822AD29974A%40wdstudio.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment