activerecord

Trouble getting started with SubSonic

I have a domain model in my head, and i am having problems building a SubSonic compatible db schema, it would realy help me get started if you could tell me how you would go at it for this example with 3 entities (could be SqlServer OR MySql doesn't matter to me) Subject- representing an educational subject (e.g. Trigonometry, Calculus)...

How to do join with SUM in ActiveRecord

Let's say I have two simple models project t.string :title vote t.references :project t.integer :value When I do loop throuh all projects, I also want to include sum of all votes, because doing projects = Project.all foreach project in projects sum = project.votes.sum(:value) ... isn't really effective. Is there...

Creating Ruby ActiveRecord objects with associations

I have Persons and Teams that have Addresses (polymorphic association) I need to create persons and addresses separately in code: person = Person.new address = Address.new and then link them together using something like: person.addressable.push(address) finally, do: person.save! This however gives a You have a nil obje...

when to ditch active record?

I'm not new to Rails but I've not done anything quite so complicated as this so far, so I'm curious what a more experienced rails developer might share: I have a sql query which joins 4 or so tables into one output: SELECT places.id, places.name, places.email, places.website, places.blurb, external_ratings.rating, photos.data_file_name...

SingleOrDefault query returns null (sometimes) even though the data is there

I'm a SubSonic newbe and am writing my first app with it. I have a database with two tables called Member and Club. The Club table has three fields which link to the primary key (ID) in the Member table (PresidentID, VicePresidentID, and TreasurerID). If I make three calls to Member.SingleOrDefault, they all return valid data. i.e.: Pre...

Multiple one-to-many associations in one model

Given two model classes, Foo and Bar, I want Foo to have 3 references to separate instances of Bar using 3 different property names, with the foreign key on the Foo table. Bar will be managed separately and can belong to many instances of Foo. This somewhat explains it, obviously has_one is the wrong association to use (I think?): Foo ...

Zend Framework - Active Record + Form Generation + Validation?

I'd like to use an Active Record design pattern in a few of my projects and I'd like to have the models, validation and form generation set up for me. Symfony is really nice for this, as is the framework I use in my day job. Is Zend Framework able to do this for me, or do I have a lot of legwork to do myself to get ZF tied in with and O...

Two related Rails models need to be created at the same time

I have a Map model, which defines the details for an ASCII-art map for a given area in a MUD. I want to be able to reach each map's page using its name instead of its ID, so if I have a map of the Western Ithmia, I want to be able to access it from /maps/western_ithmia (but also /maps/withmia). I have a second model, MapAlias, which con...

How to get most recent single item from many with ActiveRecord associations?

I'm having some issues with my code. This is probably due to some design fault. I've tried several things. Here are two. Issue: I have a 1 (lending) - N (contracts) relation. I'd like to call lending.current_contract which would return the last relevant contract. Optimization is also an issue. I'd like to call :lending, :include => :con...

ActiveRecord interfering with Logger

It appears that using ActiveRecord (which requires ActiveSupport) messes with the Logger class, resulting in difficulties. This can be seen with some example code: require 'rubygems' #require 'activerecord' require 'logger' log = Logger.new(STDERR) log.sev_threshold = Logger::INFO log.datetime_format = "%Y-%m-%d %H:%M:%S" log.debug "...

Kohana ORM - How can I do this?

Having never worked with ORM before I thought I would give it a try today, I've come across my first problem that I don't know how to solve (due to my lack of understanding how ORM really works.) Say I have three tables: Languages, Codes, and a pivot table Codes_Languages. These all have properly defined relationships in the models. No...

SubSonic3 VB.Net Add,Update, FirstOrDefault Problems

Hi, I hade build sctive record dal with subsonic3 Vb.net templates. and i am dealing with alot of bugs in the sub sonic dlls. 1)in Add() function: (i have fix) when indx has counter in the db the returnd new key type is decimal the active record fil have an exception "Public member 'Change Type To' n type 'Decimal' not found". i manage...

How to render all records from a nested set into a real html tree

I'm using the awesome_nested_set plugin in my Rails project. I have two models that look like this (simplified): class Customer < ActiveRecord::Base has_many :categories end class Category < ActiveRecord::Base belongs_to :customer # Columns in the categories table: lft, rgt and parent_id acts_as_nested_set :scope => :customer_...

Aliasing activerecord methods inside plugin

I'm trying to write a plugin that aliases some methods in ActiveRecord in the following fashion: class Foo < ActiveRecord::Base include MyOwnPlugin acts_as_my_own_plugin :methods => [:bar] def bar puts 'do something' end end Inside the plugin: module MyOwnPlugin def self.included(base) base.class_eval do ...

Create a dropdownlist using ActiveRecord

I have a table called ProjectRegion. It has two columns, an id and a title. I successfully use ActiveRecord to get all the rows. I want to create a drop down list where I assign the id column to the value and the title to the text. I suspect I'll be able to do something like- ProjectRegion[] projRegion = ProjectRegion.FindAll(); DropDow...

Inserting an invalid ActiveRecord date to a MySQL database

MySQL allows the value of "0000-00-00" for date fields, however ActiveRecords treats an assignment to a Date value with that string as being nil. I have a legacy application that relies on that exact field content for the notion of "Never", so if the customer last payment date is "0000-00-00" it acknowledges as being "Never" paid. Is t...

How to Determine if Rails Association is Eager Loaded?

Does anyone know a way to determine if a Rails association has been eager loaded? My situation: I have a result set where sometimes one of the associations is eager loaded, and sometimes it isn't. If it isn't eager-loaded, then I want to look up associations using ActiveRecord's find. If it is eager loaded, I want to use detect. ...

rails - activerecord ... grab first result

I want to grab the most recent entry from a table. If I was just using sql, you could do Select top 1 * from table ORDER BY EntryDate DESC I'd like to know if there is a good active record way of doing this. I could do something like: table.find(:order => 'EntryDate DESC').first But it seems like that would grab the entire result ...

Better SQL - :group vs. :select => 'DISTINCT'

Let's assume three models, standard joins: class Mailbox < ActiveRecord::Base has_many :addresses has_many :domains, :through => :addresses end class Address < ActiveRecord::Base belongs_to :mailbox belongs_to :domain end class Domain < ActiveRecord::Base has_many :addresses has_many :mailboxes, :through => :addresses end ...

ActiveRecord error messages: translation for fields

I've used the instructions specifies in http://guides.rubyonrails.org/i18n.html to translate fields of my model, but the labels doesn't come translated. What I'm doing wrong. I have a User model with the field name and I'd like to have it translated to Brazilian Portugues (pt_br), so I got my pt_br.yml: pt_br: errors: "Erro!" a...