Displaying 20 results from an estimated 2000 matches similar to: "Has Many :through associations"
2006 Mar 19
3
Table belongs_to either of two other tables?
Suppose I have a site about books and authors, and users can leave
comments on either a book or an author.
I''d want to have a table called "comments", which could belong to either
an author OR a book.
In my structure I wouldn''t be sure whether to include an "author_id" or
a "book_id", or both.
What would be the best way to handle this
2005 Dec 29
3
Verification problems
Hello,
Hope this isn''t a newbie question - but I don''t seem to be able to find
relevent information elsewhere.
I am having trouble getting the following to work:
Schema
======
ActiveRecord::Schema.define(:version => 1) do
create_table "authors", :force => true do |t|
t.column "name", :string
end
create_table "books", :force =>
2006 Dec 20
7
has_many :through does it support collection_singular_ids ?
Good evening list members,
I have the following model:
class Author < ActiveRecord::Base
has_many :authorships
has_many :books, :through => : authorships
end
Should I be able to do the following?
Author.find(:first).book_ids = [1,2,3]
I ask, because it doesn''t. The docs state that it should, but it
doesn''t specialise in the case of a :through
This
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit
books each month to be reviewed by other users. I have the following
relationships defined:
# the join model
book_review.rb
belongs_to :user
belongs_to :book
end
book.rb
# each book is reviewed by many users. This allows us to get the BookReview
# objects associated with this book
has_many :book_reviews,
2006 Mar 31
2
A.R. Associations problem
Hello,
I''m learning A.R Associations by creating a simple forum that consists
of 3 tables: ahuthors, topics and posts. This is the schema:
class AddAuthorAndTopicAndPostTables < ActiveRecord::Migration
def self.up
create_table :authors do |t|
t.column :username, :string
t.column :email, :string
t.column :created_on, :datetime
end
create_table
2005 Mar 08
19
find_by_sql ON STEROID possible?
find_by_sql BREAKS THE OOP BEAUTY and perhaps we can solve that.
NAMING CONVENTIONS can perhaps make find_by_sql much more clever.
lets imagine that relation:
publishers <- books <-> authors_books <-> authors -> universities (can''t find
something else than university for that last association :) )
imagine we want to fetch every book and every associated
2006 Mar 18
1
Need help .. Rails Recipes, in_place_editor, selecting associations
Hi,
I am currently reading the Rails Recipes book and like the chapter on
providing your own in_place_editor for enumerations / selects.
I understood so far, or I believe that I understood ;-), how to do that
for a field that uses values only, like choosing from "red", "black",
"green". What I fail to understand is how to chose from associated objects?!
2010 Jun 29
3
belongs_to. Association methods don't pass data to DB
Hi.
I have a problem with the association methods which passed to a model
through a belongs_to declaration. Here''s an illustration of the issue:
GIVEN:
# migration
class CreateArticlesAndAuthorsTables < ActiveRecord::Migration
def self.up
create_table :articles do |t|
t.text :title
t.integer :author_id
end
create_table :authors do |t|
t.text
2006 Nov 04
6
Problem with installing/running domU OS on HVM machine
Hi,
I have problem installing or running domU OS (Windows XP or Redhat 7.3).
The machine runs CentOS 4.4 X86_64, Xen-3.0.3. Paravirtual domU works
without problem.
The problem is that when I run command "xm create <config>", nothing
would happen. hvmloader does not seem get started at all. I''ve tried
installing both 64bit and 32bit vnc, sdl but did not see any
2006 Jan 22
2
suggest for "ambiguous column" when JOIN associated tables
Today I face with incorrect behavior in ActiveRecord.
It take place when I try to use :include parameter for .find method.
Where are two typical cases:
1. You have record with self-referential joins
CREATE TABLE keywords (id, group_id);
class Keyword < ActiveRecord::Base
belongs_to :group,
:class_name => "Keyword",
:foreign_key =>
2006 Sep 21
0
post.author_id or post.author ? Rails bug?
Hi all!
I have just found something very strange.
Let''s imagine that I have posts that belong to an author.
If I do the following (the order doesn''t matter):
apost.author = Author.find(3)
apost.author_id = 2
I get a post that has both an :author_id => 2 attribute, and an
associated Author with id 3.
Then, post.save, and the author_id in the DB is 3.
I think that this
2009 May 24
6
belongs_to not saving foreign key
Under Rails 2.3.2 using a completely brand new project, I have 2
models:
class Author < ActiveRecord::Base
# name:string
end
class Book < ActiveRecord::Base
# title:string
belongs_to :author # author_id
end
And a simple test where i create a Book with an Author using the
belongs_to and then update the foreign key directly:
require ''test_helper''
class BookTest
2014 Apr 16
0
Configure restful web service in rails
Hi,
I am trying to create a Rest web service in my rails application. I need to
configure urls for it as below.
localhost:3000/book/book_id/new/param1/param2/param3/param4/...
localhost:3000/book/book_id/next
localhost:3000/book/book_id/delete
I dont have a view pages for it since it returns in json format.Please
help.So what is the best way to configure these urls via
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 18
6
Naming join models
I''ve been playing around with EdgeRails and checking out some of the
new features. The one that will probably have the biggest affect on
my designs is join models (or :through associations). For those not
familiar with this feature, it lets you replace your habtm
association with a pair of has_many associations indirected through
an intermediate model class.
Looks like good
2009 Aug 17
1
Problem with setter override on ActiveRecord
(This message was originally written on StackOverflow -- the
formatting is much prettier there --
http://stackoverflow.com/questions/1283046/problem-with-setter-override-on-activerecord)
This is not exactly a question, it''s rather a report on how I solved
an issue with write_attribute when the attribute is an object, on
Rails'' Active Record. I hope this can be useful to others
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
Has anybody noticed validates_uniqueness_of missing in rails 3.0 rc2? I''m not sure if this is a bug or I''m just doing something wrong.
Here''s what I''m doing.
Class 1:
class Title < ActiveRecord::Base
validates_length_of :language, :is => 3
validates_uniqueness_of :language, :scope => :book_id
validate :language,
2009 Aug 10
1
Call AR belongs_to association accessor ID method on object assignment
Hi,
Haven''t been able to find this raised before but I''m sure it must have
been. When assigning an object to a belongs_to association I would
like it to call the *association*_id= method instead of directly
updating the attributes array. This is because I want to modify the
behaviour when assigning a particular object without writing separate
methods for whether it''s
2005 Nov 08
0
TX/RX ring buffer allocation (xen-unstable)
Hi,
I did not find any hints in the web where to configure/setup/manipulate
the rx/tx ring buffer allocation within dom0 for xen-unstable, maybe
someone here can nudge me towards the right knob.
The problem: when booting a handful of domUs and connecting them
(comprising a small experimental IP network with links and nodes etc.),
some interfaces that have been given by the configuration files
2009 Dec 26
3
Does :class_name for belongs_to have to be a string and why?
Seemingly, when I use a symbol, I get an ActiveRecord error stating
''Can''t convert symbol into String.'' Why can''t I use a symbol here?
Possibly this is a deeper misunderstanding of symbols in general on my
part.
#ActiveRecord error
class Book < ActiveRecord::Base
belongs_to :author, :class_name => :Person, :foreign_key
=> :author_id
end
#works