activerecord

Nested named scopes with joins (explosive error)

So I have an ActiveRecord class with a couple different named scopes that include join parameters. While running a report, I happen to have a situation where one gets called inside of the other: 1 Model.scope_with_some_joins.find_in_batches do |models| 2 models.each do |mdl| 3 other_comparisons = Model.scope_with_other_joins 4 ...

accepts_nested_attributes_for and select tag

Hi, I've a Room model and a Person model. A room can have many person and a person can have one room. On the room creation screen I can 'link' n person to this new room So i want to have a variable amount of select tag which contains the list of all people I don't know how to build the select tag. Can anyone help thanks... I've th...

ActiveRecord and Oracle bind variables

We have decided to use Rails/Oracle for a new project. My understanding is that ActiveRecord does not support bind variables and that this hamstrings Oracle's ability to cache queries and leads to significant performance problems. Cursor sharing has been said to help, but not completely, solve this problem. If this description is reas...

how to store/model users/faceboook users/linkedin users, etc, with ActiveRecord?

My app has "normal" users: those which come through a typical signup page facebook(FB) users: those which come from Facebook connect "FB-normal" users: a user that can log with both email/password * FB connect Further, there's the a slew of other openID-ish login methods (I don't think openID itself will be acceptable since it doesn...

Why is SubSonic and ActiveRecord throwing an exception when updating a record?

I have the following table in MS SQL Server 2008 Standard Edition: CREATE TABLE [dbo].[NewTestQueue]( [JobID] [int] IDENTITY(1,1) NOT NULL, [ServerName] [varchar](50) NULL, [DomainID] [int] NOT NULL, [Action] [varchar](50) NULL, [Folder] [varchar](150) NULL, [Method] [varchar](50) NULL, [ActionProfile] [varch...

TIBQuery.Unidirectional = True. How can I rewrite code ?

I have many methods in legacy code that use a TIBQuery (Interbase) with Unidirectional property = False. The problem is that users sometimes get out of memory exception. I suspect it could be fixed by setting this property to True as there is no need to cache the records. Of course I don't want to broke the old code but I also want to f...

Fetching second level model with rails active record

Hello, I have a relationship in which a post belongs to the city which inturn belongs to a state like: class Post < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base belongs_to :state end Now i want to find all the posts along with the their cities and the states to which the belong to. I w...

Adding callbacks for model classes in separate file (RoR)

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment, I would like to have a separate file which modifies Message by adding a callback. So, instead of doing: # app/models/message.rb class Message < ActiveRecord::Base before_save :foo def foo puts 'foo!' end end I would like to b...

Associate User with Account in Rails

Hello, I'm very new to Rails (this is my first project). I have a situation where an account can have many users and projects, and users can have many projects and vice versa. I have authlogic running on my Users model. I'm confused about where to go after this. After creating a new user, how do I pass the user information into account?...

why is this rails association loading individually after an eager load?

I'm trying to avoid the N+1 queries problem with eager loading, but it's not working. The associated models are still being loaded individually. Here are the relevant ActiveRecords and their relationships: class Player < ActiveRecord::Base has_one :tableau end Class Tableau < ActiveRecord::Base belongs_to :player has_many :table...

How do I create a 'Most Recently Popular' bar for content in Ruby on Rails?

I'm a noob so please forgive if this is an easy question but I'm trying to create a 'Most Recently Popular' output for specific content on a rails project. Right now the object I am pulling from has an attribute revision.background_title. I want to calculate popularity by finding the number of specific background_title's added over the...

Plans for eager loading for ActiveRecord in Subsonic 3?

Just curious if there are plans for eager loading using ActiveRecord in Subsonic 3. Is there a roadmap out there? It seems like a pretty sweet library. Very similar to Rails but missing a few sweet spots. ...

Question about Cucumber/Pickle

Hi, I'm trying to get a little more familiarity with Rails / ActiveRecord. In trying to do so I am attempting to use Cucumber to help with some "discovery" tests. I have the following Feature: Describing a task In order to work with tasks As a user I want to be able to know what makes up a task and to improve my understanding ...

has_one :through through a join model

Hello all, I want to build something so that a person can have many email addresses and an email address has only one person, but because I also have another model called Company that also can have many email addresses, and I don't want to have columns company_id and person_id in the Emails table, so I thought I can do ... person.rb ha...

bypass attr_accessible/protected in rails

I have a model that, when it instantiates an object, also creates another object with the same user id. class Foo > ActiveRecord::Base after_create: create_bar private def create_bar Bar.create(:user_id => user_id #and other attributes) end end In Bar.rb I have attr_protected to protect it from hackers. class Bar > ActiveRecord...

Is there a drop-in replacement for ActiveRecord to_xml that's faster?

I have a large-ish array (~400 elements) of ActiveRecord objects that I need to convert to XML. I've used array.to_xml for convenience, but it's very slow -- about 20 seconds when the server is busy, and about 5 seconds when idle. I've just run a few benchmarks while the server was idle, and found that: the ActiveRecord query (comple...

rails: how to add child association through a text field?

Hello all, I have two models: Company and Person class Person < ActiveRecord::Base belongs_to :company end class Company < ActiveRecord::Base has_many :people accepts_nested_attributes_for :people, :allow_destroy => true, :reject_if => proc {|attrs| attrs.all? {|k,v| v.blank? } } end And my HTML form partial for new and edit a...

Rails: Getting an array of values from a model for a time period

So, I have two models, User and Thing. User has_many :things end Thing belongs_to :user end Thing has a date associated with it. A user might add zero things one day, and 4 the next, and 7 the day after that, then zero for a few days. You get the idea. Now, what I'd like to get is an array of values for the last 7 days. How many...

Need help optimizing this database query...

I was hoping I could get some help optimizing this query for a rails site: Vacation has_many :departures has_many :photos Departure belongs_to :vacation Photo belongs_to :vacation I need to find a list of vacations ordered and displayed by departure. So if a vacation has two departures, it should show up in the list twice (once for...

ActiveRecord has_many where two columns in table A are primary keys in table B

I have a model, Couple, which has two columns, first_person_id and second_person_id and another model, Person, whose primary key is person_id and has the column name Here's the usage I want: #including 'Person' model for eager loading, this is crucial for me c = Couple.find(:all, :include => :persons)[0] puts "#{c.first_person.name} an...