activerecord

Exception pages in development mode take upwards of 15-30 seconds to render, why is that?

I am using Rails 3 beta 4 and for some reason I have each exception taking 15-30 seconds to show. Here is my trace: Started GET "/something/something/approvals/new" for 127.0.0.1 at Thu Jun 24 21:17:12 -0400 2010 SQL (1.8ms) describe `approvals_users` SQL (24.6ms) describe `clients_users` SQL (1.4ms) describe `agencies_users` ...

How to Model Multiple Relationships in ActiveRecord?

Hi, I am trying to finish building a Rails "Home Inventory" app as an example to help me learn rails. Following gives a general overview of what I am trying to achieve: The main purpose of this application is to show a page with detailed information. So, http://localhost:3000/living-room-couch would display the information regardin...

Failed to batch insert in Subsonic3 with error "Must declare the scalar variable..."

I have met a problem about inserting multiple rows in a batch with Subsonic3. My development environment includes: 1. Visual Studio 2010, but use .NET 3.5 2. Active Record Mode in SubSonic 3.0.0.4 3. SQL Server 2005 express 4. Northwind sample database I am using Active Reecord mode to insert mutiple "Product" into table "Products". I...

After find() does ActiveRecord support accessing/seeking in memory row by particular field value (BESIDES seeking using primary key)?

In the .Net universe I can use an arbitrary SELECT statement and load many rows into DataTable object. I can then find various DataRows using various field criteria (Name='Jack', Age=34, etc.). In Ruby on Rails, after doing this to load all employees into memory rs = Employee.find(:all) I want to seek a row based an arbitrary crit...

Rails - generating .sqlite3-databases

Hi everybody. My rails app. uses mysql database and I need to generate .sqlite3.databases. Is it possible to use activerecord and rails models for it? We are trying now to use models namespaced by Remote:: module but by this way we can't start concurrent generators. ...

Does Ruby on Rails' ActiveRecord support "disconnected recordsets" (like ADO.net)?

Using Microsoft's ADO.net, one can you query database -> disconnect database connection -> query/manipulate locally -> connect again (re-synchronize local with database). I've found value in this as overall it can minimize database hits. Does ActiveRecord support such a model/pattern? ...

How can I make my ActiveRecord objects only exist for 5 minutes in Ruby on Rails?

I've created a model called Request, which is created when one user makes a request with another user. I'd like each request to only exist for 5 minutes. Is this possible? ...

Foreign key (class_id) not populating in belongs_to association

Hello, I'm new to rails and building a small test app on rails3 (beta4). I am using Authlogic to manage user sessions (setup in a standard fashion as per this tutorial) I have scaffolded and setup a card model (a post basically), and set up the basic active record associations for a belongs_to and has_many relationship user.rb has_m...

Rails: Image Upload with Tableless Model

Here is the scenario, i would like the user to input all the data and all and use em to populate a result. I won't need to store them in a database since i will just be showing them a result page. I did http://railscasts.com/episodes/219-active-model and made my model tableless. But now i have a problem when i wanna receive image uploa...

Return ActiveRecord query as variable, not hash?

I am doing an ActiveRecord find on a model as such @foo = MyModel.find(:all, :select => 'year') As you can see, I only need the year column from this, so my ideal output would be ["2008", "2009", "2010"] Instead, though, I get an a hash of the models, with each one containing the year, as such: [#<MyModel year: "2008">, #<MyModel ...

Creating migrations for SQL views in rails with boolean values

Iam using SQLite wit a view like this one: CREATE VIEW view_importaciones AS SELECT fecha_importacion, COUNT(DISTINCT(total)) - 1 AS total, COUNT(DISTINCT(errores)) -1 AS errores, estado FROM ( SELECT fecha_importacion, id AS total, 0 as errores, estado FROM marcas WHERE parent_id = 0 UNION SE...

Inventory SQL Query without UNION ?

I'm designing an inventory system, it has users, products, buy_leads, orders (authorized buy_leads), inputs and outputs. class Product < ActiveRecord::Base has_many :buy_leads end class BuyLead < ActiveRecord::Base belongs_to :product has_one :order end class Order < ActiveRecord::Base belongs_to :buy_lead belongs_to :user, ...

Why can't records with piggy-back attributes be saved?

I recently run into a problem where records were marked as readonly. Checking out the documentation I found this: "Records loaded through joins with piggy-back attributes will be marked as read only since they cannot be saved. " Why not? My model looks like the following: class MailAccount belongs_to :account, :class_name => "Use...

Is there a way to check if a record was built by another model in active record?

hey, When using accepts_nested_attributes_for, I got stuck when having a validation which required the original to be present. The code will help clear up that sentence. class Foo < ActiveRecord::Base has_one :bar accepts_nested_attributes :bar end class Bar < ActiveRecord::Base #property name: string belongs_to :foo valida...

ActiveRecord::Base.connection.update(sql) sometimes returns incorrent number of affected rows

I have a production web site with the following environment: Rails 2.3.5 MySQL Server 5.1.33 Enterprise Ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux] mysql gem 2.7 Old version of BackgrounDRb plugin running on 4 different servers for background tasks, with 5 different workers each (Ruby threads, not separate processes!). One ...

Activerecord :condition syntax of an empty field?

What is the rails activerecord syntax for select records with an empty field? For example, I want to find all the records that the middle_name field is empty (length of the string < 1) for a user database. Thanks! ...

SQL LENGTH in ActiveRecord?

How can I translate this MySQL's WHERE to ActiveRecord :condition? SELECT * FROM users WHERE LENGTH(users.last_name) < 3 Thanks! ...

ActiveRecord Find - Skipping Records or Getting Every Nth Record

I'd like to do a query where I select a bunch of data, but I'd like to be able to then decrease the resolution of that data by only selecting, say, every third record, or maybe even every hundredth record, or whatever. Is there any straightforward way to do this with ActiveRecord? ...

Rails find confusion

Please help me get the include right. Poem has_many :awards has_one :overall_ranking Award belongs_to :poem # before # has_one :overall_ranking, :foreign_key => :poem_id ## SOLUTION # after has_one :overall_ranking, :foreign_key => :poem_id, :primary_key => :poem_id OverallRanking belongs_to :poem update: Award.a...

Associating MongoMapper Object to ActiveRecord Object?

What's the recommended way to do the following: class Property include MongoMapper::Document key :key key :value belongs_to :post end class Post < ActiveRecord::Base has_many :properties end Does that work (testing now)? Update, adding this to ActiveRecord is a start: ActiveRecord::Base.class_eval do def new? new_...