Displaying 20 results from an estimated 25 matches for "book_id".
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 works fine BTW:
Author.find(:first).authorship_ids = [12,13]
Do I really need to find and add (<<) my associated join models for
books one...
2006 Mar 04
10
Help setting up relationships needed
...ould list all notes the user has entered for
all books chronologically like this.
Book One: This is the note.
Book Four: This is the note.
Book One: A different note, entered later.
Right now my models are:
User
has_many :books
Book
has_many :notes
belongs_to :user
Note (has column book_id)
belongs_to :book
has_one :book
The NotesController has:
@books = current_user.books.find(:all)
@notes = @books.notes
In my views/notes/list.rhtml I can get all the notes fine, but what I
can''t get is what book they belong to.
<% for note in @notes %>
Doesn''t wo...
2006 Mar 19
3
Table belongs_to either of two other tables?
...out 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 relationship?
Thanks in advance for any help,
Jeff
--
Posted via http://www.ruby-forum.com/.
2010 Aug 28
1
validates_uniqueness_of missing in rails 3.0 rc2?
...f 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, :is_proper_language_code
validates_presence_of :value
belongs_to :book
def is_proper_language_code
errors.add(:base, "invalid language code") unless !ISO_639::ISO_639_2.find{ |lang| lang[0] == self.language }.nil?
en...
2006 Mar 18
1
Need help .. Rails Recipes, in_place_editor, selecting associations
..."Book", the book s/he
is currently reading. Both "Reader" and "Book" are model objects. How would
you go about at view to make the current book selectable?
With above mentioned Rails Recipe "Making Your Own JavaScript Helper" it
is trivial to make the IDs (book_id) selectable, but I would rather like the
user to select from a list of book titles than from a list of book ids.
If I provide the in_place_editor with the ids and titles of the available
book as select options it works on the surface (book titles can be chosen,
ids are used for the update calls)...
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 routes.
--
You received this message beca...
2006 Jun 13
0
question about saving associations when using has_many :through
...< self
user.save!
end
unfortunately, when I add a new book model to the list of
books_to_review, it doesn''t actually insert the book model into the
book_reviews table. I can of course do the following instead:
users.each do |user|
book_review = BookReview.new("book_id" => self.id)
user.book_reviews << book_review
user.save!
end
I was hoping that rais would be smart enough in the first case to add
a new book record to the book_reviews table, filling in the book_id
and user_id parameters, but instead it doesn''t even save it....
2006 Aug 11
2
User Favorites
...users can add certain ''objects'' to their
list of favorites.
Here is my current structure (simplified)
class User
has_many :favorites
end
class Book
belongs_to :favorites
end
class Favorite
belongs_to :user
has_one :book
end
The table favorite just has a two fields : user_id, book_id
Is this how you would do it? What method would you have in User to get
a list of favorite books?
Thanks for reading and any thoughts you may have of this!
Neil
2006 Jan 18
2
categories/recipes & books/descriptions - has_many vs has_one => id question
People,
In the cookbook eg, categories has_many recipes but in a book eg, book
has_one description - doesn''t that mean that the id of the description
should be the same as the id of the book (instead of having it''s own
"description_id" in the book table?
Thanks,
Phil.
--
Philip Rhoades
Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney
2005 May 25
2
URLS and Human Factors
...ibrary.com/books/tomsawyer/chapters <= list of chapters in book
http://www.library.com/books/tomsawyer/chapters/1 <= content from chapter one
using this table structure (with example data):
table books:
-id: 56
-title: tomsawyer
table chapters:
-id: 459
-sequence: 1
-book_id: 56
-content: "Tom!"
The mysql request for
http://www.library.com/books/tomsawyer/chapters/1 would look something
like:
"select content from chapters as c, books as b where b.title =
"tomsawyer" and c.sequence = "1" and b.id = c.book_id"
Thinking out...
2007 Aug 23
3
AAF: find_by_contents on AR Association Total Hits
I seem to be getting some behaviour thats unexpected (for me anyway)
when using find_by_contents on an ActiveRecord has_many association. The
results that are returned are only the records that belong to the model
returned, but the total_hits that are being returned appear to be for
the whole table.
e.g.
class Book < AR::Base
has_many :pages
end
class Page < AR::Base
belongs_to :book
2006 Jun 07
10
habtm "AND" find conditions
I have two tables and a join table for them
e.g. books, authors in a many to many relationship (habtm) and a join
table books_authors.
I can successfully search for a book that has
"author.id = 2 OR author.id = 4"
but I am unable to search for
"author.id = 2 AND author.id = 4"
This is because the result of all the joins only has one author.id
column so no single row has
2010 Sep 21
25
Working in install acts_as_commentable, On create, error: "unknown attribute: book_id"
Hello, I''m working to install the acts_as_commentable plugin on my
Rails 3 app.
After adding "acts_as_commentable" to my book model, I then added a
comment form on my book show view:
<% form_for(@comment) do|f| %>
<%= f.hidden_field :book_id %>
<%= f.label :comment %><br />
<%= f.text_area :comment %>
<%= f.submit "Post Comment" %>
<% end %>
Then in the controller (comments_controller.rb),
def create
@comment = Comment.new(params[:comment])
Book.comments.create(:title => &q...
2007 Aug 15
3
ActsAsList specs
..." do
it "should act as a list" do
Page.ancestors.should be_include(ActiveRecord::Acts::List::InstanceMethods)
end
it "should use page_index as position_column" do
Page.new.position_column.should == "page_index"
end
it "should have scope of book_id" do
Page.new.scope_condition.should == "book_id IS NULL"
end
end
it at least lets you drive adding acts_as_list? Any thoughts on how I
can improve this? How anyone else has done this?
Cheers,
Steve
2007 Jul 24
11
Mock or Stub strategy for 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, :scope => :book_id
end
What I want to do is just confirm that the validates uniqueness_of clause is
set and functioning correctly in the spec for the clipping model.
So if I was using fixtures I would do something like
it "should not allow duplicate clips in the same book" do
clip = clips( :some_clip )...
2011 Feb 07
2
Search HABTM relationship in ActiveRecord
Consider the following scenario:
Book has_and_belong_to_many Category.
In other words, a category may have a lot of books, and a book can
have more than one category.
What is the best practice to query all books related to some specified
categories.
For example, if I have following books
"From Java To Ruby" - Category: Java, Ruby
"Ruby Programming" - Category: Ruby
2005 Mar 08
19
find_by_sql ON STEROID possible?
...on at once:
SELECT b.*,
p.*,
a.*,
u.*
FROM books b,
publishers p,
authors a,
authors_books ab,
universities u
WHERE b.publisher_id = p.id and
a.id = ab.author_id and
b.id = ab.book_id and
a.university_id = u.id
that fetch every association in the (publisher book author university) db model
active record is based on NAMING CONVENTIONS so why can''t we do that?
(no matter if it''s fastidious because it''s optimization time of the dev process...
2006 May 10
7
has_many :through scope on join attribute
Hi
I have a has_many :through. It''s a basic mapping of
Project
id
....
User
id
....
TeamMembers
project_id
user_id
role
What I would like to do is have different roles so I can have in the project
model
has_many :core_members, :through => :team_members, :source => :user
but I would like to limit this to only those with the "core" role in the
team members table for
2006 Jul 06
0
Paging with multiple tables/models
...d with having a seperate object that combines the two (and
is paginated), having one of my two objects select and join/union, but
neither seems completely bug free and clean.
Any ideas?
Thanks.
- Jim
If it helps...
movie_borrower columns: id, user_id, movie_id
book_borrower columns: id, user_id, book_id
2006 Apr 05
0
Has Many :through associations
...en_in => "Denmark"
)
david.authorships.first.written_in # => "Denmark"
david.books.first # => awrd
Ok, fine and good. So how do I remove the created authorship? The only
way I have found is this:
Authorship.find(:first,
:conditions => ["author_id = ? and book_id = ?",
david.id, awrd.id]).destroy
That doesn''t seem like the "Rails" way of doing things. I hoping that I
am missing something. Can anyone help me?
--
Posted via http://www.ruby-forum.com/.