activerecord

ActiveRecord::Base Without Table (rails)

This came up a bit ago (http://stackoverflow.com/questions/399490) but it looks like the Rails plugin mentioned is not maintained (http://agilewebdevelopment.com/plugins/activerecord_base_without_table). Is there no way to do this with ActiveRecord as is? If not, is there any way to get ActiveRecord validation rules without using Activ...

how to map non-standard table with ActiveRecord or should I use other ORM?

Hello, I'm using a tool(UltraSms) that required three tables named (smsin, smsout & smsparts) I need these tables to be used in the same Rails application that has other tables. With ActiveRecrod I know that table names has to be plural of the Active record class name by convention. Is there a way to map those to an ActiveRecrod class...

Pattern for unidirectional has_many join?

It occurred to me that if I have a has_many join, where the foreign model does not have a belongs_to, and so the join is one way, then I don't actually need a foreign key. We could have a column, category_ids, which stores a marshaled Array of IDs which we can pass to find. So here is an untested example: class page < AR def categ...

Which PHP Framework is most closely cloned to ActiveRecord (RoR)

As the question says it all. Which framework in PHP is most closely cloned to ActiveRecord (Ruby on Rail). I have gone through many frameworks claiming to be based on ActiveRecord ideology but unfortunately none really come any close to ActiveRecord. Wny? Are there any such frameworks that I have missed? ...

Rails: has_many :through problem

Hi! I have problems with getting a has_many through association to work. I keep getting this exception: Article.find(1).warehouses.build ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :entries in model Article These are the models involved: class Article < ActiveRecord::Base has...

ActiveRecord::StatementInvalid: Mysql::Error:

I tried to google hardcore to get what creates this problem, but nothing helped me, so i'm triing to write here! while doing: User.create(:name => "daniel") or User.new(:name => 'daniel').save in the rails console, i get this error ActiveRecord::StatementInvalid: Mysql::Error: Duplicate entry '5' for key 1: INSERT INTO users (name, s...

Configuring NCache with nHibernate and Castle ActiveRecord

Hi, We've a relatively mature website using Castle's ActiveRecord for it's persistance pattern (along with nHiberante). We've been using single node caching and so could rely on the built in ASP.Net cache and simply use ActiveRecord's Cache tag on our entities ([ActiveRecord(Cache = CacheEnum.ReadWrite)]). This works fine, and NHProf ha...

How can I use % in a :conditions argument to ActiveRecord.find?

I'm trying to do a query like this: Widget.find(:all, :conditions => ["name like %awesome%"]) However, I'm getting a "malformed format string" exception from sanitize_sql, specifying the "%" as the problem. How can I perform this query? ...

validate at least one in has_and_belongs_to_many

I have a model with: has_and_belongs_to_many :users How do I validate that the model has at least one user in the model? I tried: validates_presence_of :users But that doesn't seem to give me what I want... ...

When validating ActiveRecord, I'm getting valid? => false but no errors in errors.count. How come?

When creating an ActiveRecord in rspec, I use fixtures for valid records. But when using the fxitures in tests, they seem to fail validation. In the following example, the employee seems to be perfectly valid, and yet the associated validation in the spec says they are invalid. class Employee < ActiveRecord::Base validates_presence_o...

Is there a way to control column order in ActiveRecord migrations?

I'd like to add a column to a table using a migration. Is there a way to add it in a particular position, rather than as the last column? I could find any "order" option in the API docs. ...

ActiveRecord relationships for a join table linking two records of the same table?

I have a Character model and a Link model. The Link model represents a link from a character to another character. A link has a textual 'description' attribute. A link from character A to character B is distinct from the opposite link from B to A. A character has zero or one link to another character. A character may have various links t...

How to sort authors by their book count with ActiveRecord?

Let's say I have Book model and an Author model. I want to list all authors sorted by their book count. What's the best way to do that? I know how to do this in SQL, either by doing where .. in with a nested select or with some join. But what I'd like to know is how to do this nicely with ActiveRecord. ...

[Active Record] How to get a list of objects with more then one initialized collection using Eager Loading and Detached Criteria?

I have a class with two many-to-many associations. After reading the AR docs I realised that I'm allowed to get only one collection at a time using eager loading. So how is it possible to get a list of objects with both initialized collections for each object using eager loading and DetachedCriteria? So far... DetachedCriteria dc = De...

How to label :id in Ruby on Rails apps?

I am building my first rails application and I expect it to eventually have many models/controllers. And of course they each have an ID associated with them. I can see that they are starting to get confusion already. In the users controller the field is called id, but in every other controller i label it as user_id. When a controller...

Adjustments needed in a Rails app to use Datamapper instead of ActiveRecord

I am trying to use Datamapper in a Rails app as an alternative to ActiveRecord. I've followed the various setup instructions and have Datamapper working in my app. But one of the first things I noticed that no longer works is this: <%= f.error_messages %> I believe this is tied to an ActiveRecord helper - is there an alternative w...

ActiveRecord dynamic attribute-based finders with Union Logic?

I want 'logical OR' dynamic finders in ActiveRecord. Anybody seen such a thing? So in the spirit of something like this.. User.find_by_name_and_email("foo", "[email protected]") .. you could do stuff like this.. User.find_by_username_or_email(user_input) ...

Getting the SQL from a Rails Migration

Hi there, Does anyone know of a way to see the SQL that would be generated by a migration (preferably without actually running the migration)? Thanks! ...

(Ruby,Rails) Dynamically connecting a model to databases in a running app...?

Hi All, I've read many of the existing questions/threads on this subject, but keep in mind that none of them have directly addressed my issue. Also keep in mind that this is NOT a situation for database.yml as I won't know the DB info in advance. That said, I need a solution for DYNAMICALLY connecting to multiple databases in a Rails ...

Does ActiveRecord support dynamic conditions in sql statements?

I want to make a SQL query in a Rails app that adds a condition when a drop-down menu is added. Obviously I don't want to search with a blank condition if the drop down is not selected. How can I develop a dynamic condition in an SQL statement? untested example: When dropdown is not selected: Object.find("billy," :conditions => {}) Wh...