activerecord

How do you discover model attributes in Rails

I started my first Rails application last fall and had to put in on the shelf for a few months when paying work sucked up all of my time. I'm now interested in getting back to the project and reading through the code to figure out where I left off. The fact that Rails dynamically creates model attributes at runtime saves a lot of repet...

Adodb Active Record vs Zend db_table

Hello I use Adodb and Active Record for database abstraction. I have started to use Zend Framework, and one of the reasons I like it so much is due to it's "Use at Will" architecture which allows me to continue using Adodb rather than Zend's db_table functionality. I have taken a look at Zend_DB_Table on paper, but really want to know...

ActiveRecord: Cache and automatically update (redundant) attributes - Best Practice

Given the following ActiveRecord models: class Tree < ActiveRecord::Base # attributes: title, price, some_date has_many :nodes end class Node < ActiveRecord::Base # attributes: title, price, some_date belongs_to :tree end A Tree has many nodes (1'000 - 2'000). For performance and other reasons I'd like to cache the price attr...

How to generate database class files with SubSonic 3?

I've been using SubSonic (ActiveRecord) for a couple of years. I've been waiting until a few of the bugs in 3.0 were fixed before downloading the newest release and upgrading my few sites that use SubSonic to 3.0. I'm currently using 2.2 on these sites. I'm working on a new site and wanted to use 3.0 to get a grip on the new updates befo...

scoped_by greater than or less than in ActiveRecord (Rails)

I want to use a dynamic scope in Rails where I filter by date. I want to do something like this: Foo.scoped_by_created_on(>the_future).scoped_by_created_on(<the_past).find(:all) Is this possible or am I stuck writing a :conditions hash? ...

STI Inheiritance in Rails. Issues with find.

I am having an issue with searching for records in my STI table due to my inheritance structure class User < ActiveRecord::Base class LegacyUser < User class AuthUser < User class SuperUser < AuthUser class FieldUser < AuthUser class ClientAdmin < AuthUser The problem is that find does not work for the AuthUser Model. The...

subsonic, mvc and activerecord

hi, i am using subsonic 3.0 and active record with a mysql database now everything is fine, but i cant seem to create views see example: public ActionResult Index() { return View(contact.GetPaged(1,20)); } now normally i would right click and choose Add View i would then choose strongly typed and find the class for the...

Check if record was just destroyed in rails

So there is record.new_record? To check if something is new I need to check if something is on it's way out. record = some_magic record.destroy record.is_destroyed? # => true Something like that. I know destroying freezes the object, so frozen? sort of works, but is there something explicitly for this task? ...

subsonic 3 and active record replacing single quotes in data

hi i am using subsonic 3 and activerecord it is my first time with this and i was just wondering if anyone can point me to some reading material with regards to inserting records. the examples i can find for adding and editing only seem to add and update the data, but i want to check the data first and replace any single quotes with dou...

Associating Two Models in Rails (user and profile)

I'm new to Rails. I'm building an app that has a user model and a profile model. I want to associate these models such that: - After the user creates an account, he is automatically sent to the "create profile" page, and the profile he creates is connected to only that particular user. - Only the user who owns the profile can edit ...

Remove assosiation instead of destroying object when :allow_destroy => true

When using the new accepts_nested_attributes_for in ActiveRecord, it's possible to use the option :allow_destroy => true. When this option is set, any hash containing nested attributes like {"_delete"=>"1", "id"=>"..."} passed to update_attributes will delete the nested object. Simple setup: class Forum < ActiveRecord::Base has_many ...

How to model interpretations of rap music

I just started working on a website that will help people understand what rappers are talking about. Users will see the lyrics to a rap song and they'll be able to click certain lyrics to see an explanation. Here's a screenshot (you can also check out the site itself here): (Original lyrics censored; click here to see them) Anyway, m...

How do I update a model object's associated object?

Hi, I want to something like the following: @user.update_attributes(:name => "Obama", :profile => { :current_location => 'US' }) where User has_one profile. ...

With Rails 2.x, how do I handle a table with a "valid" column?

I've got a table that includes a column named "valid". This has caused a problem after updating to Rails 2. ActiveRecord is expecting "def valid?" to do validation, not return a boolean value from the database. How do I work around this problem? Is renaming the column my only option? ...

Rails, ActiveRecord: how do I get the results of an association plus some condition?

hi, I have two models, user and group. I also have a joining table groups_users. I have an association in the group model: has_many :groups_users has_many :users, :through=> :groups_users I would like to add pending_users which would be the same as the users association but contain some conditions. I wish to set it up as an associatio...

Use a Criteria on top of another Criteria

I have a question on criteria: How can i use a Criteria (or similar) that filters and/or do whatever with another criteria? Something like: select clients.* from (select * from clients) as clients The real problem is something else, but achieving this behaviour would be terrific... (btw, both java and .net are welcome to help) ...

What is the proper way to remove a many-to-many connection?

I have Addresses, Lists, and AddressListMemberships. In this particular application there are over a thousand Lists and many thousands of Addresses. I've implemented a UI page to let users control a List's Addresses. I've added these actions... class ListsController < ApplicationController # ... def add_address @list = List....

SubSonic Active Record object doesn't return as IQueryable<>?

When creating a DomainService, within .NET Ria Services and using Subsonic I can add a IQueryable method as follows: public IQueryable<Server> GetServers() { return Server.All(); } It compiles with no problem but when I add a method to get a specific server: public IQueryable<Server> GetServer(int serverID) { return Server.SingleOrDe...

How to create a has_many relationship between two models, with several models in between? (Ruby on Rails ActiveRecord)

What I'd like to do is join one model to another using two intermediary models in between..Here's the abstraction: Country has_many Companies Company has_many Buildings, Company belongs_to Country Building has_many Rooms, Building belongs_to Company Room belongs_to Building I want to be able to do Country.first.rooms, so I thought th...

How to ensure sqlite isn't caching specific select queries?

I'm in the situation that I'm using sqlite with ActiveRecord and Rails (also, this is JRuby and so I'm actually using the jdbcsqlite adapter, in case that matters). Now, I'm trying to insert a row into the table attention_seekers, but only if there is no other existing similar row. Accordingly, unless AttentionSeeker.find(:first, :con...