similar to: Multiple Associations, Multiple Joins

Displaying 20 results from an estimated 9000 matches similar to: "Multiple Associations, Multiple Joins"

2007 Jul 26
1
Bi-directional self-referential HABTM
Hi, I''m having a little trouble figuring out how to make a self- referential HABTM bi-directional. I have a Employee class. Each employee can have a couple of bosses, who are also employees. The employee class has the following HABTM: has_and_belongs_to_many :bosses, :class_name => "Employee", :join_table => "bosses_courses", :association_foreign_key =>
2006 Feb 14
6
Multiple associations to the same class
Hi, I cannot seem to create associations like this: class Project < ActiveRecord::Base belongs_to :manager, :class_name => ''User'', :foreign_key => ''manager'' belongs_to :liaison, :class_name => ''User'', :foreign_key => ''liaison'' end p = Project.new p.manager => 1 trying to retrieve associated objects
2005 Sep 28
0
search engine, select the selected option
hey, i have a search engine that let u search on the an employee how can i make that if the user select "employee1" , on the next page "employee1" is selected this is my code (rhtml) <tr> <td><label for="employee_id">Employee</label></td> <td colspan="3"><%= select "employee", "id",
2006 Jan 30
1
Multiple associations between tables - do they ever work?
This is really bugging me. How can I get a second association to work between 2 tables. I have two models, User and Article. A user has many articles, and an article belongs to one user. Then I have the "current article", which is a the article that the user is currently viewing/editing. I want to track/save this value, so they can come back to the same article if they log out
2006 Jan 22
2
suggest for "ambiguous column" when JOIN associated tables
Today I face with incorrect behavior in ActiveRecord. It take place when I try to use :include parameter for .find method. Where are two typical cases: 1. You have record with self-referential joins CREATE TABLE keywords (id, group_id); class Keyword < ActiveRecord::Base belongs_to :group, :class_name => "Keyword", :foreign_key =>
2007 Jul 09
3
NoMethodError when using find_by_sql
I''m try to verify users on login. Here is my code: def self.authenticate(username,password,account_code) employee = self.find(:all, :select => "e.id, e.first_name, e.last_name, e.username, e.account_id, e.department_id, o.pay_type_id, o.admin_yn, o.payroll_yn, o.files_yn, o.dept_report_yn,e.salt, e.hashed_password", :conditions => ["e.deleted_yn=0 and
2006 Feb 03
1
nested has_many associations
My question is whether the rails helper methods for handling associations can be nested (see examples below). I suspect not as currently I''m getting "unknown method" if I try and use two associations in one call. The essence of the code is class User << ActiveRecord::Base has_many :items class Items << ActiveRecord::Base has_many :reservations belongs_to
2007 Aug 30
0
execute joins manually without :include parameter
Hi! I have the next model with the follow associations: class XmlGen < ActiveRecord::Base set_primary_key "pk" belongs_to :serie, :foreign_key => "series_fk" class Serie < ActiveRecord::Base set_primary_key "pk" belongs_to :study, #Relaciones entre las clases Study y Series. A study has many series. :foreign_key =>
2006 Jan 06
0
bug rails activerecord association join
hi, I found a bug in ActiveRecord association SQL INNER JOIN codes. in has_many, has_one, habtm and belongs_to queries the foreign key is determined from the table name of reflection and self. but that''s worng because if you use a global prefix or suffix for your tables the foreign keys will be in format of PREFIX_CLASSNAME_SUFFIX_id which is wrong, because it breaks the advantage of
2006 May 20
3
In a find, can''t you use both :include and :limit ?
I''m trying to do a find that includes a join. It has to be a find because I''m using the results for a Pagination, so I need to limit my query to the number of results I want to display per page. Here''s the type of thing I want to do: Employee table <-> Skills_Employees table <-> Skills table Let''s say I want to find all the employees who have
2006 Mar 24
2
Change to has_many :through associations
Hi everyone. I''ve made a default change to has_many :through associations that I felt was important to make before they''re released. This is after some tickets and confusion I''ve seen regarding has_many :through. class Connection < ActiveRecord::Base belongs_to :user belongs_to :channel end class Channel < ActiveRecord::Base has_many :connections
2010 Aug 19
1
Composite primary keys and :joins=>
I have a legacy db with the following simplified structure: Table-A: type_key, code_key, name, ... # PKs are type_key and code_key, there is no id col and I cannot alter this db Table-B: # each row has only the code as a foreign_key, the type_key is hard-coded to "FOOKEY" an_id, code, ... Models: class TableB < AR::Base set_table_name ''table_b''
2006 Nov 10
3
Move variables from session to ActiveRecord?
Buildings have units. Units have rooms. Rooms have people. I can grab building, room, and people IDs and store them in a session[:variable]. However, when creating a new unit, I need to give that session[:building_id] to ActiveRecord for creation. I''m not sure whether to use hidden fields or do it all in the model ''before_validation'' - in either case I
2006 Mar 31
3
Complex Through Statement
Quick Overview: I have an ''Employee'', some ''Merchants'' and some ''Products''. A ''Merchant'' has many ''Products''. An ''Employee'' has multiple ''Merchants'', depending on their relationship. For example, the Employee may be the enrollment contact for one merchant and the
2006 Mar 29
3
Self-referential many-many joins with :through
I thought I had this nailed but.. now I''m seeing spots.. I''ve included my models below, feel free to ignore them. I''m really just after an example that works. I couldnt find one on the wiki... which is fair enough considering Ricks patch: http://dev.rubyonrails.org/changeset/4022 that fixed them only went through 5 days ago.. Cheers -henster
2006 Nov 26
5
associations help?
I have Users who can "own" Projects. There is only one owner. Users in general can be authorized to view certain projects. Here is my initial stab at this: class User < ActiveRecord::Base has_many :projects # ownership has_many :project_viewers, :dependent => :destroy has_many :projects, :through => :project_viewers, :uniq => true ... end class
2006 Feb 10
3
[Req] polymorphic associations howto
Hi people, I''m looking into polymorphic associations as a way to cleanup some messy parts of my code. I think they will allow me to do exectly what I need, but since there''s little to none written on this subject, I''d be delighted if someone could shed some light on this. Especially what the different options and needed table structures need to be. Thanks, -
2008 Apr 21
1
Urgent ActiveRecord has_many Problem - Please Help
Hi Guys, I''ve been looking everywhere for an answer to this but so far without success. I have three models: 1) employees has_many :memberships has_many :projects, :through => :membership 2) projects has_many :memberships has_many :employees, :through => :membership 3) membership belongs_to :employees belongs_to :projects Membership is used to join employees
2006 Jul 15
3
How bad is it to have 7 joins in my find_by_sql?
My question is whether there''s a more idiomatic rails way of structuring this query or of redoing the underlying models. First, the ugly find_by_sql code, which is the method to generate an atom feed: def atom items_per_feed = 15 sql_query = "SELECT activities.*, users.real_name AS real_name, accounts.last_scraped_at AS last_scraped_at,
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
Hello everyone, first post to the list and a relative newbie to Rails development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I would kick the tires on Rails to see if it can speed up development for internal applications. Anyway, I am running into a problem that is just driving me crazy and everything I read on the net doesn''t seem to help. I was hoping someone here might