similar to: has_many + finder_sql

Displaying 20 results from an estimated 6000 matches similar to: "has_many + finder_sql"

2006 Feb 13
0
has_many finder_sql #{id} single/double quotes voodoo
I never would have figured this out in many moons: has_many :subscribers, :class_name => "Person", :finder_sql => ''SELECT DISTINCT people.* '' + ''FROM people p, post_subscriptions ps '' + ''WHERE ps.post_id = #{id} AND ps.person_id = p.id '' + ''ORDER BY p.first_name'' Variable
2006 Feb 28
3
[AR] #{id} namespace visibility used in finder_sql
Dears, [Rails 1.0.0] I''m working with a legacy schema, and around my 20+ models i''ve used some AR constructs. They are based on a finder_sql doing some dirty sql and using #{id} from the ''pivot'' model for extracting data in other tables. like : class Division < ActiveRecord::Base set_table_name "legacy_division" set_primary_key
2006 Jun 09
1
finder_sql issue with has_many :through
I have an inner join query that Action Record can''t seem to pull off conventionally, so I''m trying to use :finder_sql to utilize an sql query that works beautifully in SQL. The problem is, when I try to call the method, I get the following: private method `gsub'' called for #<Array:0x267de04> Here is my has_many code: has_many :mod_privileges,
2006 Jan 04
5
habtm recusive
I have a people table: CREATE TABLE people ( id int(10) unsigned NOT NULL auto_increment, first_name varchar(75) default NULL, middle_name varchar(75) default NULL, last_name varchar(75) default NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1272 ; and a people_people table: CREATE TABLE people_people ( person_id int(11) unsigned NOT NULL,
2006 Aug 15
2
has_many + finder_sql & :include
Hello, In a model I have: has_many :things, :finder_sql => '' select * from other_things '' + '' where id = #{id} '' When I do MyClass.find(:all, :include => :things) I get a weird error: from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing. I have two tables with two parallel one-to-many relationships. I wish to use the :finder_sql parameter to essentially ''or'' the two foreign keys. What isn''t working for me is performing a ''sub-search''. Let''s say the tables are "stores" and
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all, My question is somewhat complicated, but bear with me. My project has a number of models: User, Program, and Team. Users belong to multiple Programs. Programs have multiple teams, but Teams belong to one program. For each Program a User belongs to, he can belong to multiple Teams. (Think of this in an athletic context where users are athletes, programs are universities). So my
2006 Aug 02
2
Self-Referential has_many :through
Hello all. I am trying to create a self-referential has_many :through. I used the following site as a guide http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through but it still doesn''t appear to be working. I have two models. Person and Relationship. A person has many contacts (Which is another person) through relationships class Person < ActiveRecord::Base
2006 Jan 06
1
has_many with :finder_sql question
hi all, I have a Class, Client, which has_many projects (Project class). the projects depend on a session_id variable, however. So the question is, how can I do the following: has_many :projects, :finder_sql => "SELECT p.* FROM projects p INNER JOIN projects_users pu ON pu.project_id = p.id WHERE pu.user_id = #{session[:user_id]}" The problem is that I need to filter a
2005 Dec 30
5
HABTM with finder_sql problem (Rails bug?)
I''m building an app that needs i18n support across the entire database (i.e. localized attributes). In order to do this I''ve created a special HABTM join table that can be associated with _any_ other table: create table language_strings ( for_table varchar(255) not null, foreign_id int not null, language_id varchar(5) not null, attr_name varchar(255) not null, value text
2005 Dec 27
3
Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
I''m sure there''s something right under my nose that I''m missing. I have two tables with two parallel one-to-many relationships. I wish to use the :finder_sql parameter to essentially ''or'' the two foreign keys. What isn''t working for me is performing a ''sub-search''. Let''s say the tables are "stores" and
2007 Nov 22
1
has_many :through questions
I''ve created the following associations using :through: class Person < ActiveRecord::Base has_many :attendees, :dependent => :destroy has_many :events, :through => :attendees, :uniq => true end class Event < ActiveRecord::Base has_many :attendees, :dependent => :destroy has_many :people, :through => :attendees, :uniq => true
2011 Sep 27
0
has_many with :finder_sql returns [nil]?
Is it supposed to do that? I find it very confusing. AR 3.0.10 class Unit has_many :units, :finder_sql => proc { "SELECT * FROM `#{table_name}` WHERE `location_id`=#{id} AND `location_type`=#{Location::UNIT}" } end Both should return []. However... >> Unit.first.units.find([1000000]) [2011-09-27 10:05:11|main|debug] Unit Load (4.0ms) SELECT `units`.* FROM `units`
2006 Jul 01
0
activerecord generating wrong syntax with postgresql
I''m using activerecord outside of rails and find_first generates sql that postgresql doesnt'' like. This is rails 1.1.4, with everything up to date via "gem update". This is the command line: ruby -rrubygems seca -c ../etc/seca.cnf cert --export 1 --format pkcs12 --key root.key >root.pfx This is the error: (PGError: ERROR: argument of WHERE must be type
2006 Dec 26
0
alias_method_chain vs. redefined method with super
I''m trying to fully understand the subtleties of using alias_method_chain to refine method behavior versus redefining a method and calling super. I have a simple data model (a music collection) that I often use to evaluate web frameworks, and I''m trying to get it working on Rails 1.2.0RC1. Specifically, I have three classes which subclass a common Artist class: - Band
2006 Apr 04
1
has_many fails where find_by_sql succeeds
Can anyone explain why the method form of the following works, but the (apparently identical) has_many fails? I have 3 sites in my fixtures. Initially, for a new StockGroup, sites_not_using_this_stock_group should return all 3 sites (which it does). When you add a site to the StockGroup, it should disappear from the output of sites_not_using_this_stock_group. But the has_many form
2006 Jan 18
3
legacy database on remote host
I''m getting this error in webrick then it crashes leaving nothing in the log. ruby: symbol lookup error: /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.so: undefined symbol: mysql_sqlstate Here is the standard query I would normally write to get the data. select * from child,parent where CONCAT(SUBSTRING(child.item_number,1,14,''00'') = parent.order_number and
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
Guys, I have a need to support as has_many/belongs_to relationship on a legacy(kind of) schema. The reason I say kind of is that the schema does have "id" columns that are used in many associations, but this particular has_many/belongs_to association needs to support different ones. I''ve attached to code at the end of this email. Suffice it to say I need to use the standard
2006 Mar 15
1
Through method problems with custom foreign_keys
A person has a many company_branches and A company_branch has many people. This join is represented using a "contacts" table. I am using a legacy schema so i am forced into using non-standard rails primary keys. I am using the new through relationship in rails 1.1. p=Person.find(1) b=p.company_branches # gives this error: ActiveRecord::StatementInvalid: OCIError: ORA-00904:
2006 Jun 07
1
has_many, through, want to store email in mysql
Hi, I''m still a new with ROR, but it''s really cool :) I just have this problem with a project of mine. I want to store email in a database. I already wrote a simple import script, that works, so that''s not a problem. Showing the email (efficiently) in a ROR site is. These tables are in the database: emails id email_id (foreign key -> emails.id) seq