Displaying 20 results from an estimated 2000 matches similar to: "Eager loading using find_by_sql"
2006 Jul 26
8
team captain - habtm w/has_one...
the below...
class User < ActiveRecord::Base
has_and_belongs_to_many :teams
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
has_one :captain, :class_name => ''User''
produces the error...
Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT *
FROM users WHERE (users.team_id = 1) LIMIT 1
i
2006 Apr 03
2
HABTM migrations
Bad rails day for Matt-
In a migration, for a habtm:
create_table :teams_users do |t|
t.column :team_id, :integer
t.column :user_id, :integer
end
Ok, fine. In a controller (well really a migration script):
@user.teams << Team.find( 3 )
And the SQL pumped at my server is:
INSERT INTO teams_users (`team_id`, `id`, `user_id`) VALUES (3, 3, 34)
Which
2006 Jan 20
11
HABTM relations
Hi,
I have 3 tables with HABTM relation.
USERS -> QUOTE_TO_USER <- QUOTES
Table QUOTE_TO_USER has 3 attributes: quote_id, user_id, component.
I have a form where I can tie multiple users to QUOTE. This is easy one,
thru "user_ids" (@quote[:user_ids] = @params[:quote][:user_ids]).
In this form I have all users and I just check those I want to tie to
this quote, however
2005 Dec 14
5
inserting multiple rows
I have table which stores multiple entries. Each row has user_id,
game_id and a pick_id. On a page the user has to make load of choices.
All this gets submitted.
the html looks like so:
<input type="hidden" name="game_id" value="3">
<input type="hidden" name="user_id" value="19">
<select name="pick[3]">
....
2007 Apr 03
2
has_many :through associated object ids assignment error
Hi,
I have the following situation:
class Article < ActiveRecord::Base
has_many :readings
has_many :users, :through => :readings
end
class Reading < ActiveRecord::Base
belongs_to :article
belongs_to :user
end
Now what I''m trying to do is:
article = Article.new
article.save!
# user ids 1,2,3 exist in database, as does the article
article.user_ids = [ 1, 2, 3 ]
But I
2006 Oct 02
2
when to use find_by_sql
I have a bunch of queries to compute some counters, like
find_by_sql(<<-SQL
SELECT p.*, c.nfavourites
FROM people p, (
SELECT fp.person_id, COUNT(fp.user_id) as nfavourites
FROM favourite_people fp, users u
WHERE fp.user_id = u.id
AND u.cluster = ''#{in_cluster_of_user.cluster}''
GROUP BY fp.person_id
) as c
WHERE
2012 Nov 13
1
help formatting data for clustering
Hi,
I'm a R beginner. I have data of this form:
user_id, brand_id1, brand_id2, .....
for example:
1 , 45 , 32, 45, 23
2 , 34
4, 11, 43, 45
I'm looking for the right procedure to be able to cluster users. I am
especially interested to know which functions to use at each step.
I am currently able to load the data in a data frame, each row's name being
the user id.
#extract user
2009 Jan 21
1
finding row and column indices of date in multiple columns of a data frame
Hi,
I have a data.frame SAMPLES with columns:
Site Site# Season Day1 Day2 Day3
Day1, Day2, Day3 are class "Date", the other columns are numeric or
factor.
I have a date "mydate" that may or may not be listed in my data.frame
and I need to find that out.
If "mydate" is there, I want to get the number of the data.frame row
where it occurs.
2007 Feb 14
3
eager loading parents and children (acts_as_tree)
I am struggling with how to do eager loading of an acts_as_tree model.
If the model Stuff acts_as_tree I know I can do this to get children as
well:
Stuff.find(:all, :include => :children)
But what if the model I am including is the one that acts_as_tree?
For example, say Picture belongs_to Category. Category acts_as_tree and
I want to get all pictures that are members of a category that
2007 Dec 12
2
possible bug in eager loading
Hello,
@users = User.find(:all, :include => {:user_data =>
:user_data_field}, :order => "username = ''someone-oHC15RC7JGTNLxjTenLetw@public.gmane.org'' desc",
:limit => 50)
This produces:
User Load IDs For Limited Eager Loading (74.648762) SELECT * FROM
(SELECT DISTINCT ON (users.id) users.id, username AS alias_0 FROM users
LEFT OUTER JOIN
2007 Dec 20
3
ActiveRecords Eager Loading
Hi,
I am doing an eager loading in ruby on rails using below statement
------------------------
Article.find(:all, :include => [:asset, :vote],
:conditions=>"assets.parent_id is null",
:order=>"stat_final_ranking desc", :limit=>20)
---------------------------------------
the above statement resulted in this expensive query.
2006 Jun 22
3
best way to generate sums of groups
I''m a rails newby, so I''m trying to wrap my head around how to tackle
this, since my first few attempts failed.
Let''s say your database looks like this:
Users
id, name, created_at
Points
id, user_id, value, created_at
Users complete different tasks and are awarded varying levels of points,
which are recorded in the Points table. What if you wanted to display a
2007 Apr 16
5
AAF: merge search results
Hi,
I have a user model that has a couple of other models(like street
address, tasks).
suppose
User has a name field
Address has a state field.
so I want to provide a detailed search form each field in the user and
its related
models can be specified.
Suppose I have a user that has a name "california", and that user has a
address with the state field being "california" as
2006 Dec 25
2
how to insert data using has_and_belongs_to_many
I''am newbie in RoR, so my question might look stupid, but I stuck in one
thing.
I''ve created 3 tables:
users{
id,
user
}
books
{
id,
book
}
books_users{
book_id,
user_id}
Model
class Book< ActiveRecord::Base
has_and_belongs_to_many:users
I can''t figure out how to insert data to the books_users table.
For example users post info about new book and information
2009 Mar 11
12
Eager loading comments associated with user submissions.
Hey everyone,
I am working on an application that allows users to submit articles,
and also comment on those articles. Pretty much exactly like Digg.
Everything works fine except that when there are a lot of comments
there are a lot of database queries to both fetch the comments and the
users who posted those comments. I have used eager loading in other
parts of my application to reduce the
2006 Apr 26
2
Multiple Select example?
I''ve been trying to sort out a multiple select dropdown but haven''t
found any good examples - anyone know of any or perhaps could make a
suggestion [see below]
Model:
1. Task AR has_many users
2. User AR belongs_to task
login/password attributes
Controller:
View:
<%= collection_select("task", "users" , @users, "id", "login", {},
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,
2011 Dec 13
2
Plotting a date variable after GAM
Dear All,
I am fitting a simple GAM model using the "gam" function in the "mgcv"
package. The only independent variable is a continuous variable
representing the time of the event (in year and month) coded so that
"0" represents January 1960, "1" represents February 1960, etc. Now
when I try to plot the results, my x-axis ranges from "-200" to
2006 Feb 08
0
foreign table references...a new twist
I thought I was on top of them all, but found another one that has me
completely stumped.
table referral_notes
belongs_to: placement
table placements
has_many: referral_notes
def list_rfn
@placement = Placement.find(:all) # possibly unnecessary
@referral_note = ReferralNote.find(:all,
:include => [:placement],
:conditions => ["placement_id = ?",
2006 Jan 19
0
Limited eager loads and conditions on the eager tables
Hi,
Why are limited eager loads and conditions on the eager tables incompatible?
Doing a find(:all) without :include causes a select * query to be generated,
which means the id fields everwrite each other if associated tables are
included using :joins.
But using :include, if conditions are placed on the tables listed in :joins
then Rails throws an exception when :limit is included too.