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?

On 16 July 2012 15:29, Jean-Sbastien D. [email protected] wrote:

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

Colin L. wrote in post #1068920:

On 16 July 2012 15:29, Jean-Sbastien D. [email protected] wrote:

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

On 16 July 2012 16:03, Jean-Sbastien D. [email protected] wrote:

Give us a clue. Are you getting an error of some sort? If so it
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 L. wrote in post #1068930:

On 16 July 2012 16:03, Jean-Sbastien D. [email protected] wrote:

Give us a clue. Are you getting an error of some sort? If so it
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

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

On 16 July 2012 16:31, Jean-Sbastien D. [email protected] wrote:

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

Colin L. wrote in post #1068932:

On 16 July 2012 16:31, Jean-Sbastien D. [email protected] wrote:

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?

On 16 July 2012 16:43, Jean-Sbastien D. [email protected] wrote:

Is it possible, or is dead wrong?
As I said it looks ok to me. Show us your db/schema.rb

Colin

On 16 July 2012 17:01, Jean-Sbastien D. [email protected] wrote:

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

Colin L. wrote in post #1068939:

On 16 July 2012 16:43, Jean-Sbastien D. [email protected] wrote:

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.

Note that this schema.rb definition is the authoritative source for

your

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

another

system, you should be using db:schema:load, not running all the

migrations

from scratch. The latter is a flawed and unsustainable approach (the

more migrations

you’ll amass, the slower it’ll run and the greater likelihood for

issues).

It’s strongly recommended to check this file into your version control

system.

ActiveRecord::Schema.define(:version => 20120713204006) do

create_table “customers”, :force => true do |t|
t.string “first”
t.string “last”
t.string “username”
t.string “password”
t.boolean “consent”
t.string “normal_avatar”
t.string “security_question”
t.string “security_answer”
t.integer “security_level”
t.integer “organization_level_id”
t.integer “version”
t.string “timezone”
t.datetime “last_visited”
t.datetime “registered_on”
t.boolean “is_activated”
t.boolean “approval_pending”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

create_table “customizeds”, :force => true do |t|
t.integer “customer_id”
t.string “background”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

create_table “date_of_births”, :force => true do |t|
t.date “customer_date”
t.integer “customer_id”
t.datetime “modify_on”
t.integer “friendship_group_id”
t.boolean “visible”
t.boolean “activated_field”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

create_table “friendship_groups”, :force => true do |t|
t.string “description”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

create_table “tv_show_managers”, :force => true do |t|
t.integer “tv_show_id”
t.integer “customer_id”
t.datetime “modify_on”
t.integer “friendship_group_id”
t.boolean “visible”
t.boolean “activated_field”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

create_table “tv_shows”, :force => true do |t|
t.string “description”
t.datetime “created_at”, :null => false
t.datetime “updated_at”, :null => false
end

end

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

On 16 July 2012 17:18, Jean-Sbastien D. [email protected] wrote:

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 L. wrote in post #1068946:

On 16 July 2012 17:18, Jean-Sbastien D. [email protected] wrote:

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

Colin
Guess so thanks for you help!

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?

Colin L. wrote in post #1068942:

On 16 July 2012 17:01, Jean-Sbastien D. [email protected] wrote:

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?

On 16 July 2012 21:30, Jean-Sbastien D. [email protected] wrote:

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