I have a couple models which are associated with the has_many belongs_to pair. For the sake of demonstration, a client has one server but a server has many clients. I might do something like this:
client1.server = the_server
client2.server = the_server
client3.server = the_server
My actual application is quite a bit more complex tha...
A bit of a newbie question on rails associations.
I have a Bug model, and a Status model. Status is basically just a key/value pair table. Out of the choices available, I would say Bug has_one Status makes the most sense. However, according to this
Content belongs_to ContentTemplate. Go
back and look at how I described the
probl...
Hi,
I have two ActiveRecord models with a hasMany / belongsTo association:
class User < ActiveRecord::Base
has_many :letters
end
class Letter < ActiveRecord::Base
belongs_to :user
end
The User model has a revision_number attribute, to which I would like to scope the belongs_to association, so the letter is associated to a User b...
Simple question by a cakephp noob:
i have two models, Player and Team.
Team has an id (int) and a cool_name (varchar).
Player has an id (int), a cool_name (varchar) and a reference for the team table, team_id (int).
Cool_name instead of name because i don't have tables in english, so i can't use the field 'name'.
So, a team hasMany ...
I am working on an an application that allows a user to search for a particular book on Amazon using a given search criterion (e.g. title, keyword, author.) I am currently attempting to store these search results to a MySQL database, but am struggling with the concept of relationships.
It seems natural that I would structure the models ...
I am building a simple book check out application. One of the things that I need to do is determine if a book is checked out. I have my associations between my people and book classes setup through a book_check_out class. My goal is to use the checked_out property of book to determine if a book is presently checked out. However, in my pr...
I've created three classes to represent Books, People, and BookLoans. While I am able to show the association of People to Books through BookLoans I've been seeding my database.
I now need to save a checkout of a book. It was my intention to do this action through the book controller. Specifically, creating a loan action in the BooksCon...
I am building an application with a fairly hefty form that is built using 11 sub-forms (and I will mention that they are all ZendX_jQuery forms).
In one of the sub-forms I have a few quirkier elements. I need a list of features about rooms in a house. So I require multiple text input boxes that belong to an array - these inputs are the...
Hello guys, I hope you can help me.
I have a User entity that has a Current Location field (city and country). To old this info I created an entity called Location which has_many Users.
I'm not entirely sure if I should put in the User model "has_one" or "belongs_to", but for what I read if I wanted it to have the foreign key of the lo...
I have two tables:
Contestant and Votes
Contestant hasMany Votes
I've tried doing a count(Vote.id) as Votes so I can place it on the
recordset and just paginate them but I have no idea where to place it.
I did it on the fields array but it gave me the total count of votes
regardless of the contestant they belong to.
The votes are link...
I have a List with the numbers (5,9,3) in it. Let's call it MyList
I would like to perform
var results = from a in myEntities.thing1 where a.ID belongsto MyList select a;
right now I do
List<T> t = new List<T>(); //I actually define T to a strong type
foreach (int i in MyList)
{
t.add(from a in myEntities.thing1 where a.ID==i sele...
Is there a better way of writing this code? It just doesn't sit right with me, I feel like there is something really 'rails like' that I should already know:
belongs_to :parent_in_use
belongs_to :parent_template
def after_create
new_parent_in_use = ParentInUse.create!(self.parent_template.attributes)
self.update_attribute(:parent_i...
Hi,
I have the following two models
class ContactField < ActiveRecord::Base
end
class Address < ContactField
end
class Phone < ContactField
end
and
class Contact < ActiveRecord::Base
end
class Company < Contact
end
class Person < Contact
end
I want one contact, no matter is it Company or Person, to have many ContactFields(Addre...
Given three models that are each nested in each other. If I create the top-level object and build_* the other child objects, I can retrieve all child objects through the relationships before and after save() on the original instance. However, if I try to retrieve the 2nd level nested object after find(:id) the original parent it fails. I...
Hi SO,
I have a simple Category model in my CakePHP application. I want to add sub-categories, and do this by simply adding a parent_id column.
The parent_id is a belongsTo relationship, that references back to the same Category model.
When I generate my admin scaffolds, a dropdown will shop up (correct!), but I'd like to include a NU...
Still pulling my hair out with Zend_Form and any elements that need to be placed in a sub-array. form->populate() does not work when working with elements within a sub-form that have been set to a parent array using belongsTo() - I think it is actually a bug in Zend_Form->setDefaults() but just wanted to see if anyone else has a) had the...
I'm creating a wiki. Each Article has_many Revisions, and an Article belongs_to a single current_revision. So in the database, Articles have a single reference to a Revision's id, and Revisions each have a single reference to the Article they belong to. Before I continue, does this seem like a sane way to do things? It strikes me as ...
I have a two models set up like this:
class User < ActiveRecord::Base
# external_id column in database
end
class UserUpload < ActiveRecord::Base
belongs_to :user, :primary_key => "external_id", :foreign_key => "external_user_id"
end
However, whenever I do
upload = UserUpload.find(id, :include => :user)
The sql that gets emitte...
I have three models A, B, and C, where A has_many B; B belongs to C, and B has a created_on timestamp. C has_many A through B.
I want to return all A where A has a B that belongs to C and where B is the most recently created B for that A.
I can do this with a method loop. Can this be done solely with named_scopes?, or is some other ...
I am running into some Rails 2.3.5 ActiveRecord behavior I do not understand. It appears that an object can have its association ids updated in inconsistent ways.
This is best explained with an example:
Create a Post model with the string attribute 'title' and a Comment model with the string attribute 'content'.
Here are the associa...