Michael Jochimsen
2005-Jun-01 00:26 UTC
associated attributes in has_and_belongs_to_many join tables are not being coerced to column types
It seems like extra attributes in join tables are not getting cast to the appropriate types when they are accessed through ActiveRecord, but are being left as strings. Consider the following table structure: CREATE TABLE people ( id int unsigned, last_name varchar(60), first_name varchar(40) ); CREATE TABLE teams ( id int unsigned, name varchar(100) ); CREATE TABLE join_people_teams ( person_id int unsigned, team_id int unsigned, joined int unsigned quit int unsigned ); Here we have two tables, people and teams, which are connected by an intermediate join table that has an extra attribute. Say that we have some data in the tables like such: people: id: 1 last_name: Doe first_name: John teams: id: 1 name: Foobar join_people_teams: person_id: 1 team_id: 1 joined: 2004 quit: 2005 Now, if we have Person and Team classes defined as follows: class Person < ActiveRecord::Base has_and_belongs_to_many :teams, :join_table => ''join_people_teams'' end class Team < ActiveRecord::Base has_and_belongs_to_many :people, :join_table => ''join_people_teams'' end then we should be able to say something like: p = Person.find(1) years = p.teams[0].quit - p.teams[0].joined But we can''t, because p.teams[0].quit and p.teams[0].joined are strings instead of integers. Does anyone know why, or have any insight as to how this can be fixed? Thanks, Michael