I have two models:
User
MentoringRelationship
MentoringRelationship is a join model that has a mentor_id column and a mentee_id column (both of these reference user_ids from the users table).
How can I specify a relation called 'mentees' on the User class that will return all of the users mentored by this user, using the MentoringRe...
Basically what's the difference between design pattern, module and some other terms we use.
...
I'm loading data from my database and I'm doing a sum calculation with a group by.
ElectricityReading.sum(:electricity_value, :group => "electricity_timestamp", :having => ["electricity_timestamp = '2010-02-14 23:30:00'"])
My data sets are extremely large, 100k upwards so I was wondering if its possible to use the find_each to batch ...
I'm trying to check if a find method returns a result. My find method is the following:
post = Post.find(:all, :conditions => { :url => params['url'] }, :limit => 1)
What would be a good way to check that post contains a result?
...
I'm encountering a problem with will_paginate while doing a complex find.
:photo has_many :tags, :through => :tagships
:item has_many :photos
:photo belongs_to :item
@photos = @item.photos.paginate :page => params[:page],
:per_page => 200,
:conditions => [ 'tags...
I have the following association in my User model:
has_and_belongs_to_many :friends, :class_name => 'User', :foreign_key => 'friend_id'
I have the following uniqueness constraint in my user_users table:
UNIQUE KEY `no_duplicate_friends` (`user_id`,`friend_id`)
In my code, I am retrieving a user's friends --> friends = user.friends....
My question is somewhat specific to my app's issue, but the answer should be instructive in terms of use cases for association logic and the record timestamp.
I have an NBA pick 'em game where I want to award badges for picking x number of games in a row correctly -- 10, 20, 30.
Here are the models, attributes, and associations in-play...
This seems like it should have a straightforward answer, but after much time on Google and SO I can't find it. It might be a case of missing the right keywords.
In my RoR application I have several models that share a specific kind of string attribute that has special validation and other functionality. The closest similar example I can...
I've looked over the Arel sources, and some of the activerecord sources for Rails 3.0, but I can't seem to glean a good answer for myself as to whether Arel will be changing our ability to use includes(), when constructing queries, for the better.
There are instances when one might want to modify the conditions on an activerecord :inclu...
Ok, so I had this working just fine before making a few controller additions and the relocation of some code. I feel like I am missing something really simple here but have spent hours trying to figure out what is going on. Here is the situation.
class Question < ActiveRecord::Base
has_many :sites
end
and
class Sites < ActiveRecor...
I am trying to limit a user of my application to voting (liking in this case) a an answer to a question a particular number of times. I am successfully stopping the collection of the user_id but the record keeps getting created. I need for the validation to actually block the creation of the record in the likes table.
As you can see ...
In my Rails application there is a model that has some has_one associations (this is a fabricated example):
class Person::Admin < ActiveRecord::Base
has_one :person_monthly_revenue
has_one :dude_monthly_niceness
accepts_nested_attributes_for :person_monthly_revenue, :dude_monthly_niceness
end
class Person::MonthlyRevenue < Active...
Hi i'm using this for getting data:
Topic.find(:all, :include => ...,
:conditions => @core ? ["cores_topics.id = ? AND visible = 1 AND (distance < ? OR cores.id IN (?))",@core.id, @user_location[3].to_i, @user_friends] :
["visible = 1 AND (distance < ? OR cores.id IN (?))", @user_location[3].to_i, @user_friends],
...
how can i rewri...
Hi,
I am build a webapp for iphone using Phonegap, and I want to create a DB on the device and not on my server.
I've seen that there is a Safari Sqlite database, but I haven't been able to find any information about using this database with active record.
Does someone knows how to do so?
Best,
Gregory
...
Hello Guys!
I have a Question class in ActiveRecord with following fields:
[ActiveRecord("`Question`")]
public class Question : ObcykaniDb<Question> {
private long id;
private IList<Question> relatedQuestions;
[PrimaryKey("`Id`")]
private long Id {
get { return this.id; }
set { this.id = value; }
}...
Is there an easy or at least elegant way to prevent duplicate entries in polymorphic has_many through associations?
I've got two models, stories and links that can be tagged. I'm making a conscious decision to not use a plugin here. I want to actually understand everything that's going on and not be dependent on someone else's code that...
Hi all,
I have a relatively simple problem. I have a model named Item which I've added a status field. The status field will only have two options (Lost or Found). So I created the following array in my Item model:
STATUS = [ [1, "Lost"], [2, "Found"]]
In my form view I added the following code which works great:
<%= collection_sele...
Is there a way to override one of the methods provided by an ActiveRecord association?
Say for example I have the following typical polymorphic has_many :through association:
class Story < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings, :order => :name
end
class Tag < ActiveRecor...
Hi,
I have a has and belongs to many relation between User and Article
models, and I would like to link them even if an article if not hosted
on the same database then a user.
For example, If an article exists at foo.com/articles/3 and a
user exists at bar.com/users/1, If would like to be able to do
from foo.com web interface or bar.co...
Hi There,
I have a table 2 tables that have a m:m relationship, what I can wanting is that when I delete a row from one of the tables I want the row in the joining table to be deleted as well, my sql is as follow,
Table 1
CREATE TABLE IF NOT EXISTS `job_feed` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`body` text NOT NULL,
`dat...