similar to: ActiveRecord introspection

Displaying 20 results from an estimated 10000 matches similar to: "ActiveRecord introspection"

2006 Aug 07
28
Dr Nic’s Magic Models
Welcome! Welcome! Welcome! Ladies and Gentlemen, today you shall be thrilled and dazzled by wonders of magical mystery. Dr Nic?s Magic Models will now be unveiled to all. Mystery and magic that you will be able to perform at home. Within your ActiveRecord models, never again will you need to write: * validates_presence_of validations * has_many and belongs_to statements * has_many
2006 May 28
7
Self-referential has_many :through relationship
Hi, I have a self-referential has_many :through relationship setup to track relationships between users. Basically relationships are modeled as a join table with an extra column ''relation''. create table relationships ( user_id integer unsigned not null, friend_id integer unsigned not null, relation char(1) not null, ) --- relations --- f = friend r = request to
2011 Nov 02
2
Specify and validate requirements on an ActiveRecord association
Looking for some guidance/support on what feels like might not be an uncommon use-case. `User.has_many accounts` `User.has_many payment_methods` `Account.belongs_to :user` `Account.belongs_to :payment_method` `PaymentMethod.has_many :accounts` There are lots of `Accounts`. When I (a `User`) want to assign accounts to a `PaymentMethod`, I really don''t want to scope against all of them,
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations, what is the ''best'' way to handle validations? As an example: class Student < ActiveRecord::Base # some attrbutes like # :name # :grade # relationships has_many :students_assignment, :dependent => :destroy has_many :assignments, :through => :students_assignment has_many
2007 Sep 16
4
How far to go with ActiveRecord unit tests without hitting the database?
I''m currently try to push my limits a little bit with some of my unit testing -- trying to avoid saving ActiveRecord objects to the database and take advantage of mock/stub objects. How far should I expect to get in this direction? From what I can tell, ActiveRecord seems to fight me when it comes to associations. In other words, many associations seem to require database queries.
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
I want to find out what are the associations with another active record class. So If my class is as below: Class Component < ActiveRecord::Base has_many :branches end class Branch < ActiveRecord::Base belongs_to :component end and then I do Component.reflections[:branches].active_record I would expect that to be Branch but it is in fact Component. The inspection of
2006 Nov 06
21
acts_as_ferret and associations
I have the following models: class Book < ActiveRecord::Base acts_as_ferret belongs_to :author end class Author < ActiveRecord::Base has_many :books end and in the controller: def search if params[:query] @query = params[:query] @total, @books = Book.full_text_search(@query, :page => (params[:page]||1)) @pages =
2010 Jul 11
10
dependent support for has_many through?
Given the following class Programmer < ActiveRecord::Base has_many :assignments has_many :projects, :through => :assignments end if I call Programmer#projects.clear, it will delete_all the joining assignments; however, I have a situation where I''d like the assignments to get destroyed instead so that their after_destroy callbacks get called. It would be simple to
2010 Feb 11
3
Parameterized ActiveRecord Associations: Any such thing?
Hi list, how are ya? So, my current project is just begging for the ability to have parameterized associations in my ActiveRecord classes. Basically I need something that is a cross between named scopes and standard associations (has_many specifically). I''m wondering if such a thing exists or, if not, if anyone else has an elegant, equivalent solution? Example: class Sprocket <
2006 Feb 07
3
help with relationship
Let''s imagine we are modelling a company that have several shops. I have a Worker model and a Shop model. A worker belongs_to a shop, and each shop has_many workers. But, in a shop there''s a distinguished worker that is the supervisor create table shops ( ... worker_id integer -- the supervisor ); How would you express this relationship?
2006 May 17
2
ActiveRecord::Associations ER diagram/macros
Hello, I found an interesting ER diagram on the "Module: ActiveRecord::Associations::ClassMethods" page of the Rails Framework Documentation : http://ar.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html At the beginning we can read ? Associations are a set of macro-like class methods for tying objects together through foreign keys. They express relationships like
2008 Nov 19
3
Overwriting / Decorating ActiveRecord association accessor
Hi, I am trying to overwrite the accessor of a has_many association. Basically my class looks like this: class Person has_many :emails has_one :link, :class_name => ''PersonProxy'' def emails_with_link link.emails + emails_without_link end alias_method_chain :emails, :link end Now that works fine if I only access the collection like >>
2005 Dec 21
2
ActiveRecord Error with << in Collection
Hi I get a following error: ActiveRecord::AssociationTypeMismatch in Cmdb#create ConfigurationItemAttributeValue expected, got Array RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/associations/association_collection.rb:128:in `raise_on_type_mismatch''
2006 Mar 02
1
ActiveRecord in modules & associations
I''d like to organise my active records into modules but can''t get the associations to work. The doc says that associations within the same module should work. I''ve tried using the class_name option too but still doesn''t work. Can anyone help? For example module Mod1 class Animal < ActiveRecord::Base has_many :dogs, :class_name =>
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like: class Company < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :companies end I understand that the belongs_to causes related companies to be read from the db when I ask for a category. I suspect SQL something like select * from categories, companies where category.id
2006 Mar 05
2
depth needed in model()
If there are models of type M in session, and objects of type M contain objects of type M'', does M'' need to be included in model()? -- fxn
2006 Jun 04
6
Activerecord relations.
I''ve got two tables set up - Things and Users where Users have many things and Things belongs to Users. They''re connected by Things.user_id => User.id and Things.updated_by_id => User.id both in the Things model using Belongs_to and custom foreign key for one of them. Problem is when I''ve got the updated_by_id belongs_to I can''t add Things using
2009 Sep 09
1
Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch Going Nuts!
Hi, I have been trying to do this for a few days now and cannot figure it out. I would be very grateful is anyone can help me I am trying to upload an attachment to AWS, S3 using paperclip, however every time I keep getting this error: ActiveRecord::AssociationTypeMismatch in ProjectController#create_notice Graphic(#37649720) expected, got Tempfile(#27280470) RAILS_ROOT:
2006 Mar 18
1
has_many and validates_associated
By trial and error I seem to arrive to the conclusion that 1. Validation recurses through has_many by default and a root save! call raises an excepcion if some child no matter how nested is fails validation 2. Validation does not recurse through has_one by default and you can change this with validates_associated, in which case exceptions behave like above
2009 Sep 10
2
Paperclip attachment to AWS - ActiveRecord::AssociationTypeMismatch
Hi, I have been trying to do this for a few days now and cannot figure it out. I would be very grateful is anyone can help me I am trying to upload an attachment to AWS, S3 using paperclip, however every time I keep getting this error: ActiveRecord::AssociationTypeMismatch in ProjectController#create_notice Graphic(#37649720) expected, got Tempfile(#27280470) RAILS_ROOT: