I feel like this is a really easy question but i've been stuck for a while.
I have three models, user, listing and admin. Please how do i make both user and listing belong to admin?
I feel like this is a really easy question but i've been stuck for a while.
I have three models, user, listing and admin. Please how do i make both user and listing belong to admin?
class Admin < ActiveRecord::Base
has_many :users
has_many :listings
end
class User < ActiveRecord::Base
belongs_to :admin
end
class Listing < ActiveRecord::Base
belongs_to :admin
end
class AddAdminUserListing < ActiveRecord::Migration
def up
create_table :admins do |a|
a.string :name
end
create_table :users do |u|
u.integer :admin_id
end
create_table :listings do |l|
l.integer :admin_id
end
end
def down
drop_table :listings
drop_table :users
drop_table :admins
end
end
If this is not what you are looking for then please clarify your question.
Information on these sorts of basic questions can be obtained at: http://guides.rubyonrails.org/
class Admin < ActiveRecord::Base
has_many :users
has_many :listings
end
class User < ActiveReecord::Base
belongs_to :admin
end
class Listing < ActiveReecord::Base
belongs_to :admin
end