similar to: Confusion with expressing many to many relationship

Displaying 20 results from an estimated 10000 matches similar to: "Confusion with expressing many to many relationship"

2006 Apr 29
2
Seeing performance problems with has_many :through relation
Greetings all, I am looking for some insight from some of the more experienced with has_many :through relationships as I am having a hard time reconciling the performance I am seeing. I have 2 tables that are linked together via has_many :through Table 1: urls ( there are about 7,000 records ) 2 fields, id and url Table 2: phrases ( there are about 87,000 records ) 2 fields, id and phrase (w/
2006 Apr 28
9
Q: Timing of render :update in an action ?
Hey folks, am hoping someone can set me straight with a solution to an issue that has come up involving the timing of rendered page elements in relation to the completion of an action''s execution. I have an ror search app which searches through two tables consisting of 7,000 page urls and a table w/ 87,000 related keyphrases within those pages. Search results can take anywhere from 2
2011 Jul 11
36
has_many and belongs_to association
Hi , I want to test the one below but I got the problem belongs_to :name, :class_name => "Phrase", :foreign_key => "name" in my test context "test"do should have_many :phrases end in language.rb belongs_to :name, :class_name => "Phrase", :foreign_key => "name" error is 1) Failure: test: check has_many and belongs_to
2008 Oct 28
3
Backwards N+1 problem
Hey, i’m running into an N+1 problem, but i don''t exactly know how to :include in this situation. (controller code is at the bottom). I''m trying to find all of the highest ranked definitions, and then render their associated phrases. A Phrase has many definitions. A Definition has many children I already have all the info i need stored in @definitions, so this should only
2006 Aug 12
7
Collection assignment to a has_many :through
I''m working on a simple photo gallery in rails, it seems to be a good project for a newbie. I have photos and categories, many-to-many association. It worked well with HABTM. Then I decided that it would be good to be able to change order of the photos so that thumbnail pages would look less chaotic. So I created a Layout model which is a join model (or whatever it is called) that
2006 May 27
7
How should I select rows from a join-model based on more than one association?
A concrete example: We''re building a system to organize the information about workshops being held in various conventions. A convention has more than one workshop, and each workshop can be held in more than one convention. Also each workshop has a host, who is specific to a workshop being held in a specific convention. For example, Matz may host an "Introduction to Ruby"
2006 May 28
7
Self-referential has_many :through relationship
Hi, I have a self-referential has_many :through relationship setup to track relationships between users. Basically relationships are modeled as a join table with an extra column ''relation''. create table relationships ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(1) not null, ) --- relations --- f = friend r = request to
2006 May 19
7
How can I set up relations for these models?
Hello! I have a legacy DB and want to use ActiveRecord for it. However, I can''t set up a relation correctly. Here''s table spec: [products] id name price [subproducts] product_id subproduct_id Some example data: [products] 1, "Computer", 500.00 2, "Monitor", 200.00 3, "Printer", 100.00 4, "System", 700.00 5, "System2",
2006 May 10
7
has_many :through scope on join attribute
Hi I have a has_many :through. It''s a basic mapping of Project id .... User id .... TeamMembers project_id user_id role What I would like to do is have different roles so I can have in the project model has_many :core_members, :through => :team_members, :source => :user but I would like to limit this to only those with the "core" role in the team members table for
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table has another "non-joiny" attribute. I went from this: has_many_and_belongs_to :jobs, :join_table => ''tablename'', :foreign_key => ''x'', :association_foreign_key => ''y'' to this: has_many :jobs, :through =>
2006 Aug 02
2
many-to-one relationship, do I need a second table?
Ok, to keep things short. Im wondering if I need a secondary relationship table to handle my many-to-one relationships. Here is an example of what I''ve written down. For instance say I want to find all of the people in a given location. class Location < AR:Base has_many :people end class Person < AR:Base belongs_to :location end My SQL tables look like: CREATE TABLE
2006 Jun 04
6
Activerecord relations.
I''ve got two tables set up - Things and Users where Users have many things and Things belongs to Users. They''re connected by Things.user_id => User.id and Things.updated_by_id => User.id both in the Things model using Belongs_to and custom foreign key for one of them. Problem is when I''ve got the updated_by_id belongs_to I can''t add Things using
2006 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being more than just an intersection table. But when I try to break the association, the break only seems "temporary": Let''s say my two tables are Users and Colors, and the join model is Favorites. user = Users.find(1) user.colors.length >> 2 c = user.colors.first >> #<Color:....>
2006 Jul 04
2
has_many working correctly only on reload!
I have this code that is using svn externals with rails EDGE working fine for the past couple of months. A couple of days ago, this code died. Even after deleting vendor/rails, this code doesnt work: class Tag < ActiveRecord::Base has_many :taggings has_many :events, :through => :taggings has_many :users, :through => :taggings end class User < ActiveRecord::Base # Virtual
2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will fail to generate proper SQL class StudentSemesterRecord < ActiveRecord::Base belongs_to :semester has_many :discipline_records, :through => :semester end class Semester < ActiveRecord::Base has_many :student_semester_records has_many :discipline_records end class DisciplineRecord <
2006 Jul 10
7
What is has_many :through really buying you over HABTM?
So having just learned how to do has_many :through as opposed to HABTM, and then, being concerned that I wouldn''t get it to work, I started thinking about these two approaches. It seems to me that the _only_ problem that the HM:T (has_many :through) approach solves that HABTM doesn''t is the issue of the potential collision of id columns between your join table and one of
2006 Jul 05
7
HABTM join table has an "ID" column - is this an issue?
All, I''m building model objects for existing tables that I cannot modify. In AWDWR, Dave says "Note that our join table has no id column...The second reason for not including an id column in the join table is that AR automatically includes all columns from the join tables when accessing rows using it. If the join table included a column called id, its id would overwrite the id
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, and a few things. Also a
2006 Mar 29
4
:through alternate
I''d like to use :through to create a web of associations like: class Thing < ActiveRecord::Base has_many :child_things, :through => :thing_thing has_many :parent_things, :through => :thing_thing, :some_other_option? end class ThingThing < ActiveRecord::Base belongs_to :thing belongs_to :child_thing, :class_name => ''Thing'', :foreign_key =>
2006 Jun 06
6
Linking two tables using a lookup table
Hi, How do I associate two different tables which have a lookup id (table) as common. I tried the has_many :table2, :through => look_up_table in my table1 model. Any hints? Thanks, Hari -- Posted via http://www.ruby-forum.com/.