Hi,

I am creating my databases and models and I need to use some
relationships. I am very new at this so any help or info at all would be
great. :)

The concept is:
There are three resources: people, items and tags.

* An item belongs to one person, the creator.
* A person can create many items.
* An item can have many tags.
* A tag can be used on many items.

Here my models:

-----------------------------------
/* models/item.rb */
class Item < ActiveRecord::Base
  belongs_to :person
  has_many :tags
end

-----------------------------------
/* models/person.rb */
class Person < ActiveRecord::Base
  has_many :items
end

-----------------------------------
/* models/tag.rb */
class Tag < ActiveRecord::Base
  /* should I use 'has_and_belongs_to_many' here? */
end



Here's the migrations:

-----------------------------------
/* db/migrate/1_create_items.rb */
class CreateItems < ActiveRecord::Migration
  def self.up
    create_table :items do |t|
      t.string :name
      t.belongs_to :person
      /* what should I put here to create a relation to tags? */
    end
  end

  def self.down
    drop_table :items
  end
end

-----------------------------------
/* db/migrate/2_create_people.rb */
class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table :people do |t|
      t.string :name
      /* do I need something here to create a relation to items? */
    end
  end

  def self.down
    drop_table :people
  end
end

-----------------------------------
/* db/migrate/3_create_tags.rb */
class CreateTags < ActiveRecord::Migration
  def self.up
    create_table :tags do |t|
      t.string :name
      /* what should I put here to create a relation to items? */
    end
  end

  def self.down
    drop_table :tags
  end
end
-- 
Posted via http://www.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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to