Displaying 19 results from an estimated 19 matches for "reflect_on_associ".
2010 Oct 06
2
reflect_on_association method
Hi all, I am having trouble trying to use reflect_on_association
method with given the simplified model:
class Order < ActiveRecord::Base
belongs_to :contractor, :class_name => "BusinessUnit"
end
I expected the reflect_on_association method to return
associated_foreign_key "contractor_id" but it returns
"business_unit_id&q...
2007 Jul 24
11
Mock or Stub strategy for validates_uniqueness_of
Hi,
I''m a bit stuck with mocking a unit test of a join model with regards to a
validates_uniqueness_of clause.
I have
class Book < AR:B
has_many :clippings
various validates_presence_of etc
end
class Clip < AR:B
has_many :clippings
various validates_presence_of etc
end
class Clipping < AR:B
belongs_to :book
belongs_to :clip
validates_uniqueness_of :clip_id,
2007 Aug 10
1
How to spec a model method
Still new to Specs...
How do I create a spec to test a model method? Specifically, here is my
spec:
#testing model
describe User do
it "should have many user roles" do
User.reflect_on_association(:user_roles).should_not be_nil
end
it "should have many roles though user roles" do
User.reflect_on_association(:roles).should_not be_nil
end
it "should know what role it has" do
#User.should
end
end
The last spec is incomplete... basically, I will want...
2006 May 14
4
searching on foreing keys
Hey all,
I''m using a simple search function. It''s working
great except for foreign keys.
I have one table pets (id,name,owner_id)
and another table people(id,name)
owner_id being a foreign key of pet pointing to people name.
here it is on the pet controller:
@paginator, @pets= paginate(:pets, :conditions =>["name OR owner_id
like
2007 Mar 18
7
How to get more informations about an association at runtime
Hi all
I''m working on a Custom Formbuilder. I want it to create me with a
single method call checkboxes for a given HABTM association.
My model looks like this:
[code=ruby]class Member < ActiveRecord::Base
has_and_belongs_to_many :preferred_music_styles,
:class_name => ''MusicStyle'',
:join_table =>
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
2007 May 23
10
Modifying Conditions for has_many at runtime in controller?
I am attempting to bring Rails into my company, and so far I have been
able to impress the senior managers with the flexibility /
configurability of Rails on ActiveScaffold. I have hit a point now
where I am stumped, and would really appreciate the help of the
community.
I have a Person ActiveRecord model that has_many Orders.
class Person < ActiveRecord::Base
has_many :orders
end
I am
2010 Apr 19
1
Problem with mongrel_rails, but works with script/server
...working perfectly when I start it with
> "script/server", but
> when ?I "use mongrel_rails start" it starts the app but on several
> controllers it breaks (not all of them though <-how come???) and when it
> braks ti shows the
> message "undefined method `reflect_on_association'' for Service:Module"
>
Do you have a model called Service? mongrel_service it also contains a
module called Service, so maybe ActiveRecord might be clashing, which
is strange.
Please provide a backtrace of the error, not just the last line of the error.
> When I set the...
2009 Jan 21
3
Nested serialization with to_json and to_xml with array and hash element
Title: Nested serialization with to_json and to_xml with array and
hash element
class Person < ActiveRecord::Base
has_one :address
has_one :job
def office()
return "Executive_Suite"
end
end
class Address < ActiveRecord::Base
belongs_to :person
end
class Job < ActiveRecord::Base
belongs_to :person
has_one :paygrade
def Title
return "Engineer"
end
end
2007 Feb 16
6
some fun functionality for all your specs
I''ve found these two snippets of code useful and would love some feedback.
first, .should_have_valid_associations
usage:
context "A new Product" do
specify "should have valid associations" do
@product.should_have_valid_associations
end
end
code: (thanks to Wilson/Defiler for converting to rspec)
module Spec
module Expectations
module Should
2006 Aug 16
0
acts_as_paranoid and alias_method_chain
...ain is near the bottom. please advise.
class << ActiveRecord::Base
def belongs_to_with_deleted(association_id, options = {})
with_deleted = options.delete :with_deleted
returning belongs_to_without_deleted(association_id, options) do
if with_deleted
reflection = reflect_on_association(association_id)
association_accessor_methods(reflection,
Caboose::Acts::BelongsToWithDeletedAssociation)
association_constructor_method(:build, reflection,
Caboose::Acts::BelongsToWithDeletedAssociation)
association_constructor_method(:create, reflect...
2007 Jan 28
0
problems with acts_as_paranoid (noticed while using acts_as_versioned)
...s_as_paranoid, I can''t figure out why it is
getting stuck in a loop:
def belongs_to_with_deleted(association_id, options = {})
with_deleted = options.delete :with_deleted
returning belongs_to_without_deleted(association_id, options) do
if with_deleted
reflection = reflect_on_association(association_id)
association_accessor_methods(reflection,
Caboose::Acts::BelongsToWithDeletedAssociation)
association_constructor_method(:build, reflection,
Caboose::Acts::BelongsToWithDeletedAssociation)
association_constructor_method(:create, reflection,...
2009 Mar 18
1
set_table_name woes, fragmented domain class
Hi all,
I''m running Rails on top of a Mongrel cluster. I have several model
classes that are going to have so many records it is not feasible to
keep them all in the same table. So I''ve split out the records into
many different tables, each with its own suffix which corresponds to
the id of the model to which all records in that particular table
belong.
For example,
2006 Aug 12
5
Administrative Console Screencast
The first administrative console screencast is now available at:
http://screencasts.visualjquery.com/demo1/
I''ve posted a bunch about the Admin Console, but it''s essentially an
automated scaffold that works as an engine.
The screencast is a quick overview of the minor things you''ll need to do
in models, environment.rb, and others, as well as ::drumroll:: a demo of
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2007 Mar 29
21
a better "should have valid associations"
This is pretty much the same as last time around, if you recall.
Thanks to Wilson for converting to the new form. I''ve added a few
lines. Basically, it iterates over your model associations and does
two things.
- First, just try to call the association. Usually fixes speeling
erors or other such silliness.
- Second, try to find a record with an :include on the association.
This
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
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated...
Let''s say I have:
article belongs_to author
But for whatever reason, I want an article to also be written
anonymously and therefore not require an author. Then I have:
Article:
belongs_to :author
validates_associated :author
But I DON''T have validates_presence_of. What I want to do is validate
that an author is valid --if it is
2006 Feb 01
7
Explanation of "alias_method"
Hi!
I''m trying to extend ActiveRecord''s find method (Rails 1.0, Ruby 1.8.2),
but I recognize a strange behaviour of the "alias_method" call.
I wrote a very simple script to explain my problem:
------------------------------------------------------
module ActiveRecordExtension
def self.included(base)
base.extend(ClassMethods)
base.class_eval do