Displaying 20 results from an estimated 101 matches for "join_table".
2006 May 16
4
Problems with multiple ''id'' columns in a join_table
I have a problem declaring a relationship through a join_table ; the SQL
generated by ActiveRecord is correct, but there are two columns called
''id'', and the final object gets the ''wrong'' column ...
Here''s a more detailed description of the data, code, and problem :-
There''s a People table, with id, name,...
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
...have a second association table
table clubs_people_applied with columns person_id, club_id
In other words, I need TWO habtm''s between the same two tables.
Where this is failing I think is in the model definitions:
Class Person < ActiveRecord::Base
has_and_belongs_to_many :clubs, :join_table => clubs_people
has_and_belongs_to_many :clubs, :join_table => clubs_people_applied
...
end
The rails api says that "WARNING: If you?re overwriting the table name
of either class, the table_name method MUST be declared underneath any
has_and_belongs_to_many declaration in order to...
2006 Jan 04
0
Re: DB Modelling the Rails way - solution by Chris Hall
Hi Chris,
Yesterday you kindly submitted an answer to my question on modelling
many to many relationships. I''ve briefly tried the proposed solution but
so far with no luck. Before I get too involved - I''d like to know if
mapping three way :join_tables is "legal" in a Rails sense. I only ask
since you put (untested) in your mail and I can''t find any docs on it.
BTW, forgive me if this is a duplicate post - I had some mailing
problems yesterday.
Kind Regards,
Eric.
Chris Hall wrote:
> I might suggest the following (and I...
2005 Dec 02
1
Bug with Postgres and/or HABTM?
Hello list,
I think I''ve found a bug in the way Rails is talking to my Postgres DB
when recording HABTM data.
My join_table looks like this:
id serial primary key,
tablea_id integer references tablea(id),
tableb_id integer references tableb(id),
other_attributes...
When Rails writes to join_table, I''d expect it to do something like:
INSERT INTO join_table (tablea_id, tableb_id) values (123,456)
or maybe
INSERT...
2006 Jan 02
5
DB Modelling the Rails way - Opinions??
Hi,
I''m trying to figure the most efficient way to model the following. I
can think of at least two ways to relate the tables but from a
client/server perspective! I''m wondering how to best (and
elegantly)relate them from an AR perspective.
A project has many people,
A person can work on many projects at any time,
A project has many roles,
A role is performed by a person,
A
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
...es
id
name
table projects
id
name
table project_roles
id
name
table project_members
id
employee_id
project_id
role_id
I then have the following ActiveRecord objects:
class Employee < ActiveRecord::Base
has_and_belongs_to_many :project_members, :join_table =>
"project_members", :class_name => "ProjectMember"
end
class Project < ActiveRecord::Base
has_and_belongs_to_many :project_members, :join_table =>
"project_members", :class_name => "ProjectMember"
end
class ProjectRole < ActiveRecord::...
2006 May 22
4
naming convention for bridge tables.
I read somewhere that the correct naming of bridge tables is in alpha order.
For example. I have two tables:
houses, and colors.
If I want to create a bridge table to associate colors with houses, I would
name the table:
colors_houses
The associations work fine.
But, if I have a table named: track_houses.
Building a bridge table called: colors_track_houses, gives me model
associaton errors.
2006 Jan 25
2
Update join_table attributes
I have two ActiveRecord classes that point at each other with a
"has_and_belongs_to_many" (habtm) relationship using a join table. The
join
table has an a few additional columns besides the _id columns.
For those of you with the Agile Web Dev w/ Rails book, it''s exactly the
same
setup as the articles<->articles_users<->users example on p240.
The habtm
2006 Jan 07
4
To Chris Hall - Re: DB Modelling the Rails way - Opinions??
...am making the asusmption that the
relationships between projects, people and roles is unlimited
(untested)
people_projects_roles (join table between people and projects and roles)
----------
person_id
role_id
project_id
class Project < ActiveRecord::Base
has_and_belongs_to_many :people, :join_table => "people_projects_roles"
has_and_belongs_to_many :roles, :join_table => "people_projects_roles"
end
class Person < ActiveRecord::Base
has_and_belongs_to_many :projects, :join_table => "people_projects_roles"
has_and_belongs_to_many :roles, :join...
2006 Jul 25
2
join in legacy DB?
I''ve got a problem with some tables that don''t follow any RAILS
standards. how do I define the join in the model when all three tables
have wacky names?
class Machine < ActiveRecord::Base
set_table_name "tbl_CodeMgmt_Host"
set_primary_key "Id"
end
class Pool < ActiveRecord::Base
set_table_name "tbl_CodeMgmt_Pool"
set_primary_key
2006 Jan 06
2
Re: Some advice on DB modeling
...iend_id` (`friend_id`),
CONSTRAINT `friends_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES
`users` (`id`),
CONSTRAINT `friends_ibfk_2` FOREIGN KEY (`friend_id`) REFERENCES
`users` (`id`)
)
My user.rb looks like this:
class User < ActiveRecord::Base
has_and_belongs_to_many :friends, :join_table => ''friends'',
:class_name => ''User'', :foreign_key => ''friend_id''
has_and_belongs_to_many :friends_of, :join_table => ''friends'',
:class_name => ''User'', :foreign_key => ''user_id&...
2006 Jan 19
0
Help with nested HABTM relationship
...me for a number of contacts already selected
from the mailing list (ll.36-41), no company names are printed. No error
is produced.
What am I doing wrong?
1 # set up the structures
2 class Prospect_list < ActiveRecord::Base
3 has_and_belongs_to_many :contacts,
4 :join_table => "prospect_lists_prospects",
5 :foreign_key => "prospect_list_id",
6 :association_foreign_key => "related_id"
7 end
8
9 class Account < ActiveRecord::Base
10 has_and_belongs_to_many :contacts,
11 :join_ta...
2006 Apr 17
3
model.models.models or model.models.find(:first).models
I the following three models which all have has_and_belongs_to_many
# User <-> UserGroup <-> Permissions
class UserGroup < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => "user_usergroup_join"
has_and_belongs_to_many :permissions, :join_table =>
"usergroup_permission_join", :uniq => true
end
I can do this:
permissions = user.user_groups.find(:first).permissions
but not:
permissions = user.user_groups.permissions
I want to ge...
2006 May 30
3
extra attributes in habtm
Hi,
Posting here since issue tracking isn''t the best place to discuss.
I can understand habtm is moving towards deprecating support for extra
attributes in join_table, and to use :through for those cases instead.
To clarify, patch<http://dev.rubyonrails.org/attachment/ticket/5216/habtm_join_table_test.patch1.diff>for
#5216 <http://dev.rubyonrails.org/ticket/5216> wasn''t looking to support
populating extra attributes in join table. But rathe...
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset
objects, how do I do this?
has_and_belongs_to_many :associated_assets, :class => "Asset",
:foreign_key => ?????, :association_foreign_key => ?????
Right now, my table has a :first_asset_id and a :second_asset_id, but I
don''t see how the objects themselves are supposed to distinguish one
from the
2007 Jan 03
3
Self-referential habtm with condition is broken
Here''s a simplistic model class.
class Person < ActiveRecord::Base
has_and_belongs_to_many :relatives,
:class_name => ''Person'', :join_table => ''relatives'',
:foreign_key => ''from_id'', :association_foreign_key => ''to_id''
has_and_belongs_to_many :brothers,
:class_name => ''Person'', :join_table => ''relatives'',
:f...
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM
support this? That is:
class Recipe < ActiveRecord::Base
has_and_belongs_to_many :recipes, :join_table => "recipes_recipes"
end
More importantly -- how does RoR support MULTIPLE self-joins? I.e., to
relate the table to itself via multiple join tables.
SFAIK, HABTM won''t support multiple self-joins because the method names
would get confused.
Could I create additional contr...
2006 May 18
8
Concatenated key
Hi all,
I started playing a couple days ago with Rails and it find it very
interesting.
But I''m a bit stuck with making it work with a concatenated primary key.
I want to use my own names for the DB fields and I''m using SQL Server
2005.
My tables look roughly like this:
CREATE TABLE USERS (
USR_ID VARCHAR(25) NOT NULL PRIMARY KEY,
USR_PASS VARCHAR(25)
)
CREATE TABLE
2005 Dec 19
4
need some help designing my messaging system
I am trying to create a messaging system for my users but I''m having a
hard time designing my db. This is what i have in mind, but I am not
sure if its the best approach.
user has_one inbox
user has_one outbox
inbox has_many messages
outbox has_many messages
inbox table
user_id
outbox table
user_id
messages table
box_id (refers to either inbox or outbox - how?)
from_id
to_id
2005 Dec 28
3
acts_as_taggable query
...gure
out how to make it use my table instead of the default.
class Tag < ActiveRecord::Base # already exists and has the required fields
like name, id & an items (counter)
end
class Item < ActiveRecord::Base
acts_as_taggable :join_class_name ''Itemtag'' # should I use join_table here?
end
class Itemtag <ActiveRecord::Base
set_table_name ''itemtags'' # note that this is different from the default
conention of tags_items
end
With the above settings I thought that the plugin would use the table I have
created but when I try to add a tag using the Tagga...