Displaying 20 results from an estimated 40000 matches similar to: "Activerecord | Understanding associations"
2005 Dec 28
1
Help needed with ActiveRecord
I am having issues with RoR/database relationships
I have 3 tables
Feeds (List of feeds)
FeedItems (List of items, feedsID)
FeedView (list of views and their list of feedsID)
I would like to be able to generate a view with the feeditems
For example, if the view has 2 feeds --> CNN & MSNBC and they both have
15 feeds in the feeditems table I want to be able to generate a view
with cnn
2006 Jan 31
1
view vs controller - data from multiple tables.
Hi all,
please pardon my question if it seems silly.. I''m trying pretty hard to
learn though. :)
I have 2 tables:
feeds (has_many feed_items)
feed_items (belongs_to feed)
Let''s say Feeds has 3 feed.names: "Things that Start with A", "Things
that start with B", "Things that start with C".
I want to print out, on one page, something like the
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
2005 May 14
2
ActiveRecord::Associations::ClassMethods Documentation Issue
I''m curious, but isn''t this example in the documentation for
ActiveRecord::Associations::ClassMethods somewhat counter-intuitive? The SQL
DDL is correct for the way it''s used in the models. But isn''t it more
logical that an author would have many posts, rather than many authors
having one post?
From
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 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
2006 Jan 26
1
Explanation on Activerecord Associations
A while back, I had some doubts on the use of associations. I still
haven''t got a satisfactory guidance so that I can spring ahead with the
project. I am trying to understand from a ruby point of view on doing
things. Basically I have a controller that gives me a list of students.
And each student may have say home address and mailing address. Hence I
can model as shown below. How do I
2011 Jul 26
1
ActiveRecord has_many associations
Given the models Country, State, City and Person as follows.
class Country < ActiveRecord::Base
has_many :states
end
class State < ActiveRecord::Base
belongs_to :country
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :state
has_many :people
end
class Person < ActiveRecord::Base
belongs_to :city
end
Is there any way that doesn''t allow to delete
2005 Jul 28
0
ActiveRecord, computed values, and associations
Is there some sort of good pattern for dealing with computed values with
Rails/ActiveRecord?
A simple example: 3 tables, classes, students, and student_class_records
(habtm style relation but contains a good deal of additional state so is
modeled explicitly)
Something like select the 10 classes with the most students. Easy enough
in SQL. So I''m using a lot of find_by_sql and
2010 Mar 10
0
Rails ActiveRecord associations autosave option
I have the following associations.
class Document < ActiveRecord::Base
has_many :document_sections, :dependent => :destroy, :autosave => true
has_many :document_items, :through => :document_sections
end
class DocumentSection < ActiveRecord::Base
belongs_to :document
has_many :document_items, :dependent => :destroy, :autosave => true
end
class DocumentItem <
2006 Feb 02
0
proposed bugfix/patch: ActiveRecord cross-module associations
Hi,
I''m still test driving the improved support for module namespaces in
rails and I''ve hit a problem with associations between AR classes in
modules and AR classes in the root namespace.
The long and short of it is I want to be able to say:
Foo::Bar.belongs_to :wibble, :class_name => "::Wibble"
If you don''t try to prefix ''Wibble''
2013 Nov 30
1
Need good tutorial on ActiveRecord associations
Hi,
I am very new to rails.. I am having hard times to understand the
ActiveRecord associations.. I tried
http://guides.rubyonrails.org/association_basics.html .. But it is not
for beginners. :)
Is there any good tutorials, to understand the concept?
Thanks
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on
2006 Apr 14
1
ActiveRecord and multiple associations
Hello,
I have a Company that has_and_belongs_to_many Persons. A Person
has_many Emails. I want to display each Person''s Email for each
Company, so I try this:
companies = Company.find(:all)
for company in companies
persons = company.persons
for person in persons
puts person.email
end
end
Unfortunately, this doesn''t work correctly. Let''s say the id of
2008 Feb 22
2
marshaling ActiveRecord objects: how to unload associations?
I''m marshaling ActiveRecord objects, and I want them to be as small as
possible. How can I unload everything that can be reloaded from the
database?
If they''re marshaled before any of the associations are referenced
then the referenced objects aren''t dumped. But if the association has
been loaded, how can I unload it? AssociationProxy.reset doesn''t seem
to do
2006 Jan 30
0
Serializing has_many associations and ActiveRecord objects
Is it possible to serialize ActiveRecord objects and ActiveRecord
children to XML?
--
Posted via http://www.ruby-forum.com/.
2012 Feb 04
0
ActiveRecord Associations not working in RSpec with Devise
Hi everyone,
I have the following classes:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :timeoutable,
:recoverable, :rememberable, :trackable, :validatable
has_many :comments, :dependent => destroy
...
end
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :commentable, :polymorphic => true
...
end
In rails console,
2006 Nov 27
2
changing activerecord associations at runtime
Is there any way to change the associations of a model at runtime,
like before running a specific query?
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this
2006 Apr 28
0
ActiveRecord associations -- when to use force_reload = true
If an Order has_many Items, when do I have to call order.items(true)
instead of just order.items to get the current list of items ?
In Rails 1.1 if I call some_item.destroy, the order.items list doesn''t
get updated unless I call order.items(true) -- this does not happen in
Rails 1.0.
Also when I add items to an order the list may or may not get updated
depending on the Rails version
2006 Jan 21
2
Testing ActiveRecord associations
How do I write a test which proves something like "Post :has_many
Comments" and "Comment :belongs_to Post"? It doesn''t seem to be covered
in "A Guide to Testing the Rails" on manuals.rubyonrails.com.
Cheers, Robert.
--
Posted via http://www.ruby-forum.com/.
2006 Dec 14
3
Problem with ActiveRecord and Associations
Hi,
I''m having what I believe to be a typecast problem with ActiveRecord and
Associations. In the code below, I need to flag a contact record for
deletion if the contact doesn''t have any addresses or books records:
sql = "select id, delete_flag from contacts where id = #{params[:id]}"
contact = Contact.find_by_sql(sql)
if (contact[0].addresses.count +