• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Rails] Question about flow

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did a little bit of Rails over the weekend for the first time in years. I'm very well versed in Grails so I'm having a few snags regarding the work flow of getting up and running. I created a new project and then I ran the initial rake db:create command. After this is where my questions are.

Following an online guide from the official web site, I created a new domain and gave it some initial properties. Then I ran rake db:migrate. Everything worked fine. I then went and created a new domain that is related to my first domain. And then I started getting all confused because I can't just go into the domain and set the associations like I want (has_many, belongs_to). I also have to manage the migrate files and get those set up correctly, which I've been unable to do.

So, this flow isn't working for me. Although it might be trivial for a more seasoned Rails person. And I can see how rake is a good thing later on down the road, but I'm having a hard time finding its usefulness when just trying to setup your primary domains. So my preferred way of working would be this....

create rails project
rake db:create
create domain
create domain
create domain
.....
when I think they are "pretty close" to what I initially need, then run rake db:migrate. That way, my initial schema file is correct and I don't already have N number of migration files to deal with, nor do I have to manually create migration files for associations up until this point. Does that make sense to anyone?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should add that part of my confusion with rake is that I created the many side of a one-to-many first. If I had created the 1 side first, it wouldn't have been a big deal. But in the real world, you don't always know exactly what these associations are going to be like right up front.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a rake db:rollback command that will reverse the last migration, assuming your migration file included the self.down definition (in many cases the down definition is dropping a table or a couple columns). I've mentioned using vim before - the railsvim plugin has a nice command :Rinvert that will create the down automatically based on the contents of the up. There might be a similar plugin for your editor/IDE of choice.

It's common, while working on a single feature, to bounce back and forth between rake db:migrate (which runs all migrations that have not yet been run) and rake db:rollback to peel back the latest migration until you know you'll got a migration file that is correct.

Getting the associations set up is a matter of adding a some_other_table_id integer column. The documentation here is fairly straight-forward:
http://guides.rubyonrails.org/association_basics.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic