activerecord

ActiveRecord returns data in ASCII-8Bit Under Ruby 1.9.2-rc1.

Further to the title, when loading data from ActiveRecord the encoding is always set to ASCII-8Bit in spite of my best efforts to force the encoding. I have entered as much detail as possible here to try and build a good error report someone could use to help me out! The project is using the following technologies: Padrino Framework R...

Rails 3 Adding an ActiveRecord Model Method

I have the following models but I cannot get the custom method reorder_action_items to work. I am obviously missing something basic. class ActionList < ActiveRecord::Base has_many :action_items scope :today, lambda { where("day = ?", Date.today) } def self.reorder_action_items(new_order) new_order.each_with_index do |...

Has many relationship in rails

Hi all, I have this relationship in a Rails app class Folder has_many :elements end class Element belongs_to :folder end My problem is this code doesn't work element = Element.first a_folder.elements << element element.save! a_folder.save! , but this one works: element.folder = a_folder element.save! Anyone can tell me why...

ActiveRecord Custom Field Method

Lets imagine that I have a custom image upload for a particular record and I add two columns into the model. thumbnail_url thumbnail_path Now lets imagine that I have a form with a :file field which is the uploaded file in multipart form. I would need to somehow have the model pickup the file within the given hash and then issue it ove...

ORM/DAO/DataMapper/ActiveRecord/TableGateway differences?

Can you, please, explain me the differences between the following database representatives, say, in PHP.: ORM DAO DataMapper ActiveRecord TableGateway Any examples would be appreciated. ...

SubSonic ActiveRecord templates: generated code produces error converting int? to int

I just started exploring SubSonic 3's ActiveRecord, and it's initial code generation has created errors. Cannot implicitly convert type 'int?' to 'int'. An explicit conversion exists (are you missing a cast?) Here's the line it throws the exception on: public override int GetHashCode() { return this.pkEmp; ...

Avoiding "Single Table Inheritance" in Rails/ActiveRecord and Legacy Schema

I am trying to integrate with a Legacy table that has a column named "type". Rails will "smartly" assume that whenever we have a 'type' column in a table, then it will try to use Single Table Inheritance. Is there anyway to avoid this? (I can't rename the column). ...

What is this "_ifbk" constraint doing in my table?

I'm working on a Rails web application with a MySQL database. I'm using migrations to modify the schema. I've just run into a problem wherein I'm getting an invalid record error on inserting a new record. The relevant tables: users id | name | email | ... academic_records id | scholar_id | gpa | ... academic_records.scholar_id is a ...

ASP.NET MVC 2 Validation - check name is unique

Hi, In a MVC + ActiveRecord scenario, would it be possible/recommendable to validate db dependent properties as part of model binding? How would you go about implementing this - custom validation attribute? A db dependent attribute could be active records ([Property(Unique=true)]. A simple example of its usage: public class Person ...

How to name Many-To-Many association? [ActiveRecord]

I have a model called Purchase and a model called TicketType. A purchase can have many ticket types, and a ticket type can have many purchases. So I have class Purchase < ActiveRecord::Base has_many :purchases_ticket_types, :class_name => 'PurchaseTicketType' has_many :ticket_types, :through => :purchases_ticket_types end class T...

Can we connect few models of a Rails 3 app to different type of database using the ActiveRecord adapter?

Let there is a rails 3 app with two models, a Project and Notification using the ActiveRecord adapter with MySql. Project has various states using state_machine and when its state changes, I want the notifications to be stored and retrieved back using MongoDb? Can this be done using rails3? ...

Active Record Store Delete

Hi, I'm having trouble deleting from active record store. I want to delete based on the session data: ActiveRecord::SessionStore::Session.find(:all).each do |s| if s.data[:userid] == 1234 s.destroy end end does not seem to work, but: ActiveRecord::SessionStore::Session.delete_all(["updated_at < ?", 12.hours.ago]) seems to...

How to make a database appear partitioned by some columns with Active::Record

Suppose a column client_id is ubiquitous through out our database, and for a given session or request, we will be 'in the context' of a client the whole time. Is there a way to simulate having each client's data stored in a separate database, while keeping them in the same table for simpler database-management ? What I want is similar ...

Changing a class of an object in ActiveRecord

Let's say I have a FireNinja < Ninja object in my database, stored using single table inheritance. Later, I realize he's really a WaterNinja < Ninja. What's the cleanest way to change him to the different subclass? Even better, I'd love to create a new WaterNinja object and just replace the old FireNinja in the DB, preserving the ID. Ed...

Ruby On Rails multiple composite primary keys question

I am a new guy in Ruby, and I have tables with these primary keys: transaction_types: transaction_type transaction_headers: transaction_type transaction_year transaction_id transaction_details: transaction_type transaction_year transaction_id city_id ticker_id tickers: city_id ticker_id Of course, those models have other non ...

ActiveRecord Versioning plugin/gem compatible with rails3?

Hi, I googled for the the plugin/gem to do the ActiveRecord versioning for Rails3. But all I've got is not compatible for Rails3. I even searched in RailsPlugins.org too, but no luck. Do you know any that is Rails3 ready? ...

Query for all users except for users with an ID in this collection

I'm trying to find all users except for users with an id that is a member of an array exclude_ids Here's what I have: User.where("id != ?", exclude_ids) This only works when exclude_ids has only 1 element. If it has more than one element, I get this error: ActiveRecord::StatementInvalid: SQLite3::SQLException: near ",": syntax er...

Is anyone using the Ambitious adapter for ActiveRecord?

http://ambition.rubyforge.org/adapters/activerecord.html What are your experiences? ...

CodeIgniter MySQL Query not returning any data, even though there definitely is data to be returned!

Hi there! I have a CI Model set up with this function and ActiveRecord: function get_open_competitions() { $this->db->select('*, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days') ->from('challenges') ->where('closingdate >','CURDATE()') ->order...

ActiveRecord::StatementInvalid (Mysql::Error: PROCEDURE db_name.proc_spName can't return a result set in the given context: ....

I have use activerecord to access data from db. It works fine in localhost but when I tried it on another server, I get the following errors: ActiveRecord::StatementInvalid (Mysql::Error: PROCEDURE db_name.proc_spName can't return a result set in the given context: CALL proc_spName(............)): /vendor/rails/activerecord/lib/acti...