Association In rails

Here what I have
tv_show.rb
class TvShow < ActiveRecord::Base

  has_many :tv_show_managers
  has_many :customers, :through => :tv_show_managers

  attr_accessible :description
end

tv_show_manager.rb
class TvShowManager < ActiveRecord::Base

  belongs_to :customer
  belongs_to :tv_show
attr_accessible :activated_field, :customer_id, :friendship_group_id,
:modify_on, :tv_show_id, :visible
end

customer.rb
class Customer < ActiveRecord::Base

  has_one :date_of_birth
  has_one :customized
  has_one :customer_state
  has_many :tv_show_managers
  has_many :tv_shows, :through => :tv_show_managers
attr_accessible :approval_pending, :consent, :first, :is_activated,
:last, :last_visited, :normal_avatar, :organization_level_id, :password,
:registered_on, :security_answer, :security_level, :security_question,
:timezone, :username, :version
end

Essentially A customer may have many managers. A Manager is assign to
one tv_show

What his wrong with my code?

Give us a clue. Are you getting an error of some sort? If so it
might be helpful to tell us what it is, we are not telepathic (at
least I am not). Don't forget to show us the bit of code generating
the error if any.

Colin

Colin Law wrote in post #1068920:

Colin Law wrote in post #1068920:

tv_show_manager.rb

Essentially A customer may have many managers. A Manager is assign to
one tv_show

What his wrong with my code?

Give us a clue. Are you getting an error of some sort? If so it
might be helpful to tell us what it is, we are not telepathic (at
least I am not). Don't forget to show us the bit of code generating
the error if any.

Colin

Sorry,

I am using activeadmin has a backend. When creating a new manager, on
the field Customer I see customer, but when it comes to show possible
tv_show it show me #<TvShow:0xb69ca84 which i am assuming is making a
reference to memory because the relations don't work. Not to sure how to
test it in Ruby console otherwise

Is it your code that is showing it wrong or is it inside activeadmin?
If it is your code then show us the bit of code displaying it. If it
is activeadmin then I can't help I am afraid.

Colin

Colin Law wrote in post #1068930:

It looks ok to me.

Colin

Colin Law wrote in post #1068932:

Colin

I believe it is active_admin, but i am just wondering if the Association
above seem to be correct, or i am totally missing the point of ruby on
rails association, like did i make mistake

It looks ok to me.

Colin

I come from mySQL where I would have 3 tables

Customer TvShowManager TvShow
JOHN JEAN tv_show_id(1) 1 Simpson
HEATHER JEAN tv_show_id(2) 2 Familly Guy
JASON JASON tv_show_id(3) 3 Simpson
                        HEATHER tv_show_id(4) 4 Batman
                        HEATHER tv_show_id(5) 5 Stargate

Customer may have many tv_show_managers, and many tv_show through
tv_show_managers

Tv_show_Managers belongs_to customer
Tv_show_Managers belongs_to tv_show

Tv_show has_one tv_show_manager
Tv_show has_one customer, through tv_show_manager

Is it possible, or is dead wrong?

As I said it looks ok to me. Show us your db/schema.rb

Colin

Colin Law wrote in post #1068939:

Is it possible, or is dead wrong?

As I said it looks ok to me. Show us your db/schema.rb

Colin

This is my schema

# encoding: UTF-8
# This file is auto-generated from the current state of the database.
Instead
# of editing this file, please use the migrations feature of Active
Record to
# incrementally modify your database, and then regenerate this schema
definition.

It looks ok to me. Not sure what you mean by reinforcing the foreign key.

Colin

Colin Law wrote in post #1068942:

Colin Law wrote in post #1068942:

# database schema. If you need to create the application database on

    t.string "security_answer"
  end
    t.integer "customer_id"
    t.datetime "created_at", :null => false
    t.datetime "created_at", :null => false

But i think its looks good, should i also reinforce in my model foreign
key so it doesnt get confused

It looks ok to me. Not sure what you mean by reinforcing the foreign
key.

Colin

In the model tv_show_manager

Tv_show_Managers belongs_to customer, foreign_key: "customer_id"
Tv_show_Managers belongs_to tv_show, foreign_key: "tv_show_id"

Is it helpfull for ruby to understand exactly which field is which or
its just a waste?

It is not required, it makes no difference to Rails, since it already
the default, but may confuse a reader as he/she will wonder why it is
there.

I suspect your problem is something to do with the way you are using activeadmin

Colin

Colin Law wrote in post #1068946:

When I do an association, I create an association by integer id field
correct? If i want to see in my form how to see the description instead
of the id how would i proceed?

To answer such basic questions I suggest you work right through some
rails tutorials. railstutorial.org is good and is free to use online.
Work right through, entering the code and checking that it works,
including doing all the exercises and then you will have a good grasp
of the basics of rails and will be able to answer these questions
yourself.

Colin