has-many

Rails 3 has_many changed?

可紊 提交于 2021-02-18 05:31:26
问题 I need to track changes (additions and deletes) of an association set up like this: has_many :listing_services has_many :services, through: :listing_services For normal attributes the easist way to do it is to check l.changes[attribute] in before_save or l.previous_changes[attribute] in after_save . The question is, what is the best way to do it for has_many attributes? 回答1: I didn't use changes method. But I'm sure that you always can use magic methods <attribute_name>_changed? and

Display has to many association activeadmin rails not working in staging but works fine in local and development

十年热恋 提交于 2020-06-29 10:36:33
问题 I have users which can have many identities, (depending on whether they login using facebook, google, or my site). In ActiveAdmin to display the identities I had the following code. ActiveAdmin.register User do menu label: 'Subscribers' ActiveAdmin.register Identity do belongs_to :user end index do selectable_column column :email column :current_sign_in_at column :sign_in_count column :created_at column "Sign-up Provider", :identities do |user| ul do user.identities.collect do |identity| li

Display has to many association activeadmin rails not working in staging but works fine in local and development

假装没事ソ 提交于 2020-06-29 10:36:27
问题 I have users which can have many identities, (depending on whether they login using facebook, google, or my site). In ActiveAdmin to display the identities I had the following code. ActiveAdmin.register User do menu label: 'Subscribers' ActiveAdmin.register Identity do belongs_to :user end index do selectable_column column :email column :current_sign_in_at column :sign_in_count column :created_at column "Sign-up Provider", :identities do |user| ul do user.identities.collect do |identity| li

Inspect object with associations

醉酒当歌 提交于 2020-02-05 10:33:11
问题 I have two models where A has_many B. If I load A including associated B as such: a = A.find(:first, include: :bs) a.inspect only shows the attributes of a: => "#<A id: 1, name: \"Test\", created_at: \"2012-07-02 21:50:32\", updated_at: \"2012-07-02 21:50:32\">" How can I do a.inspect such that it displays all associated a.bs ? 回答1: You can't do that by default. It might create too many problems and side effects with inspecting objects. However you could extend inspect yourself with something

Inspect object with associations

不问归期 提交于 2020-02-05 10:32:26
问题 I have two models where A has_many B. If I load A including associated B as such: a = A.find(:first, include: :bs) a.inspect only shows the attributes of a: => "#<A id: 1, name: \"Test\", created_at: \"2012-07-02 21:50:32\", updated_at: \"2012-07-02 21:50:32\">" How can I do a.inspect such that it displays all associated a.bs ? 回答1: You can't do that by default. It might create too many problems and side effects with inspecting objects. However you could extend inspect yourself with something

How to get the max ID in a Join Query in Laravel 5 (Integrity constraint violation:)

微笑、不失礼 提交于 2020-01-24 15:25:31
问题 My query is like this: $deals=DB::table('leadsheet') ->join('Deal', 'leadsheet.leadcode', '=', 'Deal.leadcode') ->join('benefits', 'leadsheet.leadcode', '=', 'benefits.leadcode') ->join('delegatedealinfo', 'leadsheet.leadcode', '=', 'delegatedealinfo.leadcode') ->join('vipbooking', 'leadsheet.leadcode', '=', 'vipbooking.leadcode') ->where('id', DB::raw("(select max(`id`) from vipbooking)")) ->where('leadsheet.leadcat', '=','Delegates') ->get(); So I have following tables: 1.leadsheet --

NHibernate explicit fluent column mapping

我们两清 提交于 2020-01-23 13:18:25
问题 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 DirectoryMap : ClassMap<Directory> { public DirectoryMap { Map(x => x.Id); HasMany(x => x.SpecialUsers).Where("Status = 0"); } } User is a join table, which SpecialUser joins against to get things like status.

NHibernate explicit fluent column mapping

六眼飞鱼酱① 提交于 2020-01-23 13:18:09
问题 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 DirectoryMap : ClassMap<Directory> { public DirectoryMap { Map(x => x.Id); HasMany(x => x.SpecialUsers).Where("Status = 0"); } } User is a join table, which SpecialUser joins against to get things like status.

NHibernate insert generates updates for collection items

给你一囗甜甜゛ 提交于 2020-01-16 17:36:58
问题 How should I configure my mappings to avoid NHibernate updating my child entities' foreign keys right after inserting them? E.g. Parent class is mapped like this: class ParentMap : ClassMap<Parent> { public ParentMap() { Id(x => x.Id) .GeneratedBy.Increment(); Map(x => x.Name); HasMany(x => x.ChildNodes) .KeyColumns.Add("Parent_id") .Cascade.All(); } } Let Parent have a bunch of Child objects: Parent p = new Parent("test"); p.ChildNodes.AddRange(GetSomeDummyNodes()); When I save the parent

Model related to itself, bi-directional

本秂侑毒 提交于 2020-01-15 09:23:27
问题 I have a people table, where people are associated with other people by id. I believe this should be done with a separate table as is standard for such relationships, but I want to be able to retrieve the associated people when viewing a single record regardless of which key this record was stored as. For instance: table: people id | first_name | last_name table: people_associations id | person_one_id | person_two_id model: person $hasMany = array( "Associates" => array( "className" =>