I have a set of fluent object mappings that looks like this:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Map(x => x.Id);
Map(x => x.Status);
}
}
public class SpecialUserMap : SubClassMap<SpecialUser>
{
public SpecialUserMap()
{
Map(x => x.Property);
}
}
public class Direct...
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...
Hi,
I've got a problem with a has_many :through association, i cant call the u1.UsersProfileAttributes.find_by_ProfileAttribute_name("icq") method, rails means that this method doesn't exist. The method u1.UsersProfileAttributes.find_by_ProfileAttribute_id(3) works correctly. u1 is a user object. I don't know whats the problem, because ...
Hi there, this is my first time posting here, looks like a great site! I'm struggling with a has_many association. I have a diary application. The Model players are as follows:
User
UserFriend
UserFoodProfile
I want to be able to get at all the foods that a user's friends have eaten. So, I want to be able to get: current_user.fri...
I have a model which has many children. I was setting/removing the children as such:
mymodel.children_ids = [1,2,3]
mymodel.save #add the children
mymodel.children_ids = [1]
mymodel.save #remove children 2,3
This works just fine, but I just realized that none of the callbacks (i.e. after_destroy) are not being called on the children m...
This is probably something very simple but I'm looking for the optimal way of retrieving all Products by Tag, so to speak. This is with Spree, so I should stick to the way they have modeled their data. It's actually Product and Taxon (like category, brand, etc.)
So if Product has_and_belongs_to_many :taxons and Taxon has_and_belongs_t...
While I'm not a complete Ruby/Rails newb, I'm still pretty green and I'm trying to figure out how to structure some model relationships. The simplest example I can think of is the idea of "recipes" for cooking.
A recipe consists of one or more ingredients and the associated quantity of each ingredient. Assume we have a master list in th...
I have a model, Couple, which has two columns, first_person_id and second_person_id and another model, Person, whose primary key is person_id and has the column name
Here's the usage I want:
#including 'Person' model for eager loading, this is crucial for me
c = Couple.find(:all, :include => :persons)[0]
puts "#{c.first_person.name} an...
My question is somewhat complicated, but bear with me. My project has a number of models: User, Program, and Team. Users belong to multiple Programs. Programs have multiple teams, but Teams belong to one program. For each Program a User belongs to, he can belong to multiple Teams. (Think of this in an athletic context where users ar...
I have 4 models: transac, transac_data, item, dvd_details
class Transac < ActiveRecord::Base
has_many :transac_datas
has_many :items, :through => :transaction_datas
end
class TransactionData < ActiveRecord::Base
belongs_to :item
belongs_to :transaction
end
class Item < ActiveRecord::Base
has_many :transaction_datas
has...
First the data model:
class Forum < ActiveRecord::Base
has_many :topics, :dependent => :destroy, :order => 'created_at desc'
end
class User < ActiveRecord::Base
has_many :topics, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :replies, :dependent => :destroy
end
class Topic < ActiveRecord::Base
be...
I am having trouble with validations on a has_many relationship where the children exist, but the parent doesn't. However, when creating/saving the parent object, I want to ensure that specific children (with certain attributes) have already been saved.
There is a Parent object that has_many Child objects. The Child objects are persiste...
I am running in to a problem while using find_or_create_by on a has_many through association.
class Permission < ActiveRecord::Base
belongs_to :user
belongs_to :role
end
class Role < ActiveRecord::Base
# DB columns: user_id, role_id
has_many :permissions
has_many :users, :through => :permissions
end
class User
has_many :...
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...
Suppose we have a photography site. Any author can subscribe to receive updates from any other author. Obviously if author A is subscribed to author B that doesn't mean that B is subscribed to A. So we build models
class Author < ActiveRecord::Base
has_many :subscriptions
has_many :subscribed_by_author, :through => :subscriptions, :...
I'm not sure if this is feasible or even preferable
But I'd like to build a has_many relationship or a conditional named_scope type relationship to ease my pain into one simple relationship instead of two.
Currently I have two models which basically contain the same information and belong to the same Model rooms thru the same key room_...
One thing with which I have long had problems, within the CakePHP framework, is defining simultaneous hasOne and hasMany relationships between two models. For example:
BlogEntry hasMany Comment
BlogEntry hasOne MostRecentComment (where MostRecentComment is the Comment with the most recent created field)
Defining these relationships in...
Hi all
I have the following model association: a student model and has_many scores.
I need to make a list showing their names and average, min, max scores. So far I am using
student.scores.average(:score) on each student, and I realise that it is doing one sql per student. How can I make the list with one joined sql?
Also how would I...
Hy,
My code:
@profile.images
and i would like to get only 10 images at time and with a 10 offset, like this
@profile.images(:limit => 10, :offset => 10)
and not like this
has_many :images, :limit => 10, :offset => 10
Then I would like to count in someway all the images for that profile.
@profile.count_images
Thanks (:
...