Search Results

Search found 676 results on 28 pages for 'polymorphic associations'.

Page 7/28 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Entity Framework Multiple associations to a table causes error 3033

    - by taylonr
    I'm using EF 3.5 SP1. I have 3 tables: Pendants PendantAccessories PartsData Basically #1 and 2 are used for product selection, so #1 has a "Number of Buttons" property and other options. #2 has fields like "Cable Type" etc. The third table contains property information for all of our parts, such as what plant it's manufactured in, it's weight etc. What I'm trying to do is set up an association between #1 and #3 and also between #2 and #3. The PK in all 3 tables is the PartNumber. I set it up between #2 and 3 by going into Mapping Details and adding a Maps to PartsData and mapping the columns. Everything worked good. I then tried the same thing between #1 and 3. However, now when I compile I get "Error 3033: Problem in Mapping Fragment starting at line 713: EntitySets 'pendants' and 'pendantAccessories' are both mapped to the table 'PartsData'. Their Primary Keys may collide." Does anyone know what I'm doing wrong here?

    Read the article

  • Sunspot / Solr full text search - how to index Rails associations

    - by Sam
    Is it possible to index through an association with Sunspot? For example, if a Customer has_many Contacts, I want a 'searchable' block on my Customer model that indexes the Contact#first_name and Contact#last_name columns for use in searches on Customer. acts_as_solr has an :include option for this. I've simply been combining the associated column names into a text field on Customer like shown below, but this doesn't seem very flexible. searchable do text :organization_name, :default_boost => 2 text :billing_address1, :default_boost => 2 text :contact_names do contacts.map { |contact| contact.to_s } end Any suggestions?

    Read the article

  • EF 4 - associations with keys that dont match

    - by Steve Ward
    We're using POCOs and have 2 entities: Item and ItemContact. There are 1 or more contacts per item. Item has as a primary key: ItemID LanguageCode ItemContact has: ItemID ContactID We cant add an association with a referrential constraint as they have differing keys. There isnt a strict primary / foreign key as languageCode isnt in ItemContact and ContactID isnt in Item. How can we go about mapping this with an association for contacts for an item if there isnt a direct link but I still want to see the contacts for an item? One of the entities originates in a database view so it is not possible to add foreign keys to the database Thanks Stephen Ward

    Read the article

  • STI and polymorphs

    - by Alexey Poimtsev
    Hi, I have problem with my code class Post < ActiveRecord::Base end class NewsArticle < Post has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at' end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true, :counter_cache => true end And on attempt go get comments for some NewsArticle i see in logs something like Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE ("comments"."commentable_id" = 1 and "comments"."commentable_type" = 'Post') ORDER BY created_at Strange that "commentable_type" = 'Post'. What's wrong? PS: Rails 2.3.5 && ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]

    Read the article

  • Labeled fixtures for associations in Rails 3 broken

    - by elsurudo
    After upgrading to Rails 3, fixtures that refer to other labelled fixtures (for relationships) stop working. Instead of finding the actual fixture with that name, the fixture label is interpreted as a string. Example: # Dog.yml sparky: name: Sparky owner: john # Person.yml john: name: John Where Dog "belongs to" person. The error message is: SQLite3::SQLException: table dogs has no column named 'owner'

    Read the article

  • XCode not saving file associations

    - by coreSOLO
    I go to xcodepreferencesfile_types, change association for file type "xyz", click apply+ok, reopen xcodepreferencesfile_types, check association for file type "xyz", its set as I just edited it. Not I quit xcode, start it again, xcodepreferencesfile_types, check association for file type "xyz", and its getting reset to its old value just like i never edited it. This is so lame, kindly suggest something :(

    Read the article

  • has_one and has_many associations: which side of the association is saved first

    - by SeeBees
    I have three simplified models: class Team < ActiveRecord::Base has_many :players has_one :coach end class Player < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end class Coach < ActiveRecord::Base belongs_to :team validates_presence_of :team_id end I use the following code to test these models: t = Team.new team.coach = Coach.new team.save! team.save! returns true. But in another test: t = Team.new team.players << Player.new team.save! team.save! gives the following error: > ActiveRecord::RecordInvalid: > Validation failed: Players is invalid > from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:1090:in > `save_without_dirty!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/dirty.rb:87:in `save_without_transactions!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in > `transaction' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:182:in > `transaction' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:208:in > `rollback_active_record_state!' from > /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/transactions.rb:200:in > `save!' from (irb):14 I figured out when team.save! is called, it first calls player.save!. player needs to validate the presence of the id of the associated team. But at the time player.save! is called, team hasn't been saved yet, and therefore, team_id doesn't yet exist for player. This fails the player's validation, so the error occurs. But on the other hand, team is saved before coach.save!, otherwise the first example will get the same error as the second. So I've concluded that when a has_many bs, a.save! will save bs prior to a. When a has_one b, a.save! will save a prior to b. If I am right, why is this the case? It doesn't seem logical to me. Why has_one and has_many association have different order in saving? Any ideas? Thanks.

    Read the article

  • LINQ to SQL: On load processing of lazy loaded associations

    - by Matt Holmes
    If I have an object that lazy loads an association with very large objects, is there a way I can do processing at the time the lazy load occurs? I thought I could use AssociateWith or LoadWith from DataLoadOptions, but there are very, very specific restrictions on what you can do in those. Basically I need to be notified when an EntitySet< decides it's time to load the associated object, so I can catch that event and do some processing on the loaded object. I don't want to simply walk through the EntitySet when I load the parent object, because that will force all the lazy loaded items to load (defeating the purpose of lazy loading entirely).

    Read the article

  • Rails: print associations in ActiveRecord inspectors

    - by marienbad
    When I print an ActiveRecord of a Department, I get: Department:0x210ec4c { :id = 3, :name = "Computer Science", ... :school_id = 3 } How can I make it give me the School instead of the School_ID? In other words, call to_s on the school found by the school_id. Just like how when I have a Department d, I can say d.school

    Read the article

  • Compare associations between domain objects in Grails

    - by user303979
    I am not sure if I am going about this the best way, but I will try to explain what I am trying to do. I have the following domain classes class User { static hasMany = [goals: Goal] } So each User has a list of Goal objects. I want to be able to take an instance of User and return 5 Users with the highest number of matching Goal objects (with the instance) in their goals list. Can someone kindly explain how I might go about doing this?

    Read the article

  • cant use Activerecord find method with associations.

    - by fenec
    here are my models: #game class Game < ActiveRecord::Base #relationships with the teams for a given game belongs_to :team_1,:class_name=>"Team",:foreign_key=>"team_1_id" belongs_to :team_2,:class_name=>"Team",:foreign_key=>"team_2_id" def self.find_games(name) items = Game.find(:all,:include=>[:team_1,:team_2] , :conditions => ["team_1.name = ?", name] ) end end #teams class Team < ActiveRecord::Base #relationships with games has_many :games, :foreign_key =>'team_1' has_many :games, :foreign_key =>'team_2' end When i execute Game.find_games("real") i get : ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: team_1.name How can i fix the problem i thought that using :include would fix the problem.

    Read the article

  • Entity Framework and associations between string keys

    - by fredrik
    Hi, I am new to Entity Framework, and ORM's for that mather. In the project that I'm involed in we have a legacy database, with all its keys as strings, case-insensitive. We are converting to MSSQL and want to use EF as ORM, but have run in to a problem. Here is an example that illustrates our problem: TableA has a primary string key, TableB has a reference to this primary key. In LINQ we write something like: var result = from t in context.TableB select t.TableA; foreach( var r in result ) Console.WriteLine( r.someFieldInTableA ); if TableA contains a primary key that reads "A", and TableB contains two rows that references TableA but with different cases in the referenceing field, "a" and "A". In our project we want both of the rows to endup in the result, but only the one with the matching case will end up there. Using the SQL Profiler, I have noticed that both of the rows are selected. Is there a way to tell Entity Framework that the keys are case insensitive? Edit:We have now tested this with NHibernate and come to the conclution that NHibernate works with case-insensitive keys. So NHibernate might be a better choice for us.I am however still interested in finding out if there is any way to change the behaviour of Entity Framework.

    Read the article

  • Grails: Querying Associations causes groovy.lang.MissingMethodException

    - by Paul
    Hi, I've got an issue with Grails where I have a test app with: class Artist { static constraints = { name() } static hasMany = [albums:Album] String name } class Album { static constraints = { name() } static hasMany = [ tracks : Track ] static belongsTo = [artist: Artist] String name } class Track { static constraints = { name() lyrics(nullable: true) } Lyrics lyrics static belongsTo = [album: Album] String name } The following query (and a more advanced, nested association query) works in the Grails Console but fails with a groovy.lang.MissingMethodException when running the app with 'run-app': def albumCriteria = tunehub.Album.createCriteria() def albumResults = albumCriteria.list { like("name", receivedAlbum) artist { like("name", receivedArtist) } // Fails here maxResults(1) } Stacktrace: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (tunehub.LyricsService$_getLyrics_closure1_closure2) values: [tunehub.LyricsService$_getLyrics_closure1_closure2@604106] Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), trim() at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy:61) at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy) (...truncated...) Any pointers?

    Read the article

  • F# numeric associations

    - by b1g3ar5
    I have a numeric association for a custom type as follows: let DiffNumerics = { new INumeric<Diff> with member op.Zero = C 0.0 member op.One = C 1.0 member op.Add(a,b) = a + b member op.Subtract(a,b) = a - b member op.Multiply(a,b) = a * b member ops.Negate(a) = Diff.negate a member ops.Abs(a) = Diff.abs a member ops.Equals(a, b) = ((=) a b) member ops.Compare(a, b) = Diff.compare a b member ops.Sign(a) = int (Diff.sign a).Val member ops.ToString(x,fmt,fmtprovider) = failwith "not implemented" member ops.Parse(s,numstyle,fmtprovider) = failwith "not implemented" } GlobalAssociations.RegisterNumericAssociation(DiffNumerics) It works fine in f# interactive, but crashes when I run, because .ElementOps is not filled correctly for a matrix of these types. Any ideas why this might be? EDIT: In fsi, the code let A = dmatrix [[Diff.C 1.;Diff.C 2.;Diff.C 3.];[Diff.C 4.;Diff.C 5.;Diff.C 6.]] let B = matrix [[1.;2.;3.];[4.;5.;6.]] gives: > A.ElementOps;; val it : INumeric<Diff> = FSI_0003.NewAD+DiffNumerics@258 > B.ElementOps;; val it : INumeric<float> = Microsoft.FSharp.Math.Instances+FloatNumerics@115 > in the debugger A.ElementOps shows: '(A).ElementOps' threw an exception of type 'System.NotSupportedException' and, for the B matrix: Microsoft.FSharp.Math.Instances+FloatNumerics@115 So somehow the DiffNumerics isn't making it to the compiled program.

    Read the article

  • Active Record Associations:

    - by jmccartie
    I'm brand new to Rails, so bear with me. I have 3 models: User, Section, and Tick. Each section is created by a user. My guess with this association: class Section < ActiveRecord::Base has_one :user end Next, each user can "tick" off a section -- only once. So for each tick, I have a section_id, user_id, and timestamps. Here's where I'm stuck. Does this call for a "has_one :through" association? If so, which direction? If not, then I'm way off. Which association works here? Thanks!

    Read the article

  • CakePhp: model recursive associations and find

    - by Petecocoon
    Hello to everybody! I've some trouble with a find() on a model on CakePhp. I have three model relationed in this way: Project(some_fields, item_id) ------belongsTo----- Item(some_fields, item_id) ------belongsTo----- User(some_fields campi, nickname) I need to do a find() and retrieve all fields from project, a field from Item and the nickname field from User. This is my code: $this->set('projects', $this->Project->find('all', array('recursive' => 2))); but my output doesn't contains the user object. I've tried with Containable behaviour but the output is the same. What is broken? Many many Thanks Peter

    Read the article

  • Django ManyToMany Membership errors making associations

    - by jmitchel3
    I'm trying to have a "member admin" in which they have hundreds of members in the group. These members can be in several groups. Admins can remove access for the member ideally in the view. I'm having trouble just creating the group. I used a ManytoManyField to get started. Ideally, the "member admin" would be able to either select existing Users OR it would be able to Add/Invite new ones via email address. Here's what I have: #views.py def membership(request): group = Group.objects.all().filter(user=request.user) GroupFormSet = modelformset_factory(Group, form=MembershipForm) if request.method == 'POST': formset = GroupFormSet(request.POST, request.FILES, queryset=group) if formset.is_valid(): formset.save(commit=False) for form in formset: form.instance.user = request.user formset.save() return render_to_response('formset.html', locals(), context_instance=RequestContext(request)) else: formset= GroupFormSet(queryset=group) return render_to_response('formset.html', locals(), context_instance=RequestContext(request)) #models.py class Group(models.Model): name = models.CharField(max_length=128) members = models.ManyToManyField(User, related_name='community_members', through='Membership') user = models.ForeignKey(User, related_name='community_creator', null=True) def __unicode__(self): return self.name class Membership(models.Model): member = models.ForeignKey(User, related_name='user_membership', blank=True, null=True) group = models.ForeignKey(Group, related_name='community_membership', blank=True, null=True) date_joined = models.DateField(auto_now=True, blank=True, null=True) class Meta: unique_together = ('member', 'group') Any ideas? Thank you for your help.

    Read the article

  • Ruby on Rails: How can I authenticate different user types from one place?

    - by sscirrus
    Hi everyone! This is my first post on Stack Overflow. I am trying to build a system that authenticates three types of user with completely different site experiences: Customers, Employers, and Vendors. I'm thinking of using a polymorphic 'User' table (using AuthLogic) with username, password, and user_type (+ AuthLogic's other required fields). If this is a good way to go, how do I set this up so after authenticating an user_id with a user_type the standard way, I can direct the user to the page that's right for them? Thanks.

    Read the article

  • Is it OK to manage associations manually?

    - by sosborn
    Here are the relevant models: User Product Order A User can sell or buy products An order has a buyer, a seller and one product I know that I can do this with a HABTM relationship between orders and user, but is seems to me like it would be simpler to put in the Order table the following columns: :seller_id :buyer_id and manage those relationships manually as orders are only created once and never edited. However, this doesn't seem very Rails-like and I am wondering if I am missing something conceptually at the HABTM relationship.

    Read the article

  • Sencha 2 : Sync models with hasMany associations in LocalStorage

    - by Alytrem
    After hours and hours trying to do this, I need your help. I have to models : Project and Task. A project hasMany tasks and a task belong to a project. Everyting works well if you don't use a store to save these models. I want to save both tasks and projects in two stores (TaskStore and ProjectStore). These stores use a LocalStorage proxy. I tried many things, and the most logical is : Ext.define('MyApp.model.Task', { extend: 'Ext.data.Model', config: { fields: [ { name: 'name', type: 'string' }, { dateFormat: 'd/m/Y g:i', name: 'start', type: 'date' }, { dateFormat: 'd/m/Y g:i', name: 'end', type: 'date' }, { name: 'status', type: 'string' } ], belongsTo: { model: 'MyApp.model.Project' } } }); Ext.define('MyApp.model.Project', { extend: 'Ext.data.Model', alias: 'model.Project', config: { hasMany: { associationKey: 'tasks', model: 'MyApp.model.Task', autoLoad: true, foreignKey: 'project_id', name: 'tasks', store: {storeId: "TaskStore"} }, fields: [ { name: 'name', type: 'string' }, { dateFormat: 'd/m/Y', name: 'start', type: 'date' }, { dateFormat: 'd/m/Y', name: 'end', type: 'date' } ] } }); This is my "main" : var project = Ext.create("MyApp.model.Project", {name: "mojo", start: "17/03/2011", end: "17/03/2012", status: "termine"}); var task = Ext.create("MyApp.model.Task", {name: "todo", start: "17/03/2011 10:00", end: "17/03/2012 19:00", status: "termine"}); project.tasks().add(task); Ext.getStore("ProjectStore").add(project); The project is added to the store, but task is not. Why ?!

    Read the article

  • Two Different Types of Associatons on the Same Two Tables in Rails

    - by tmo256
    I have two models, users and themes, that I'm currently joining in a HABTM association in a themes_users table. Basically, after a user creates a new theme, it becomes available to other users to select for their own use. However, only the original creator of the theme should have the ability to edit it. So, I need to have some other kind of association to handle that relationship, something like an created_by_id field in the theme. In this way, the user model acts as two different roles: they can be an implementer of a theme AND/OR the owner of the theme. The implementer relationship is handled by the themes_users join table; the question is: What is the right way to handle this secondary association? Do I need to make users polymorphic and then make the created_by_id reference an "owner"? Or is there something easier? Thanks so much for your help!

    Read the article

  • How do I check if an instance has an object to skip displaying the values?

    - by Angela
    I have created a polymorphic association around a model called status. Some contacts will have a status associated with it. Many won't. If I try to call a status when one is not there, I get an error. Right now, even if I haven't created a status for the model, it still runs whatever is in the if-end block. Here's what I am trying, but it's not working: <% if [email protected]? %> <p>Status: <%= @status.find(:last).status %></p> <% end %> In the controller, it is defined below: @status = Contact.find(@contact).statuses By the way, also open to make code more readable and DRY.

    Read the article

  • One-to-many Associations Empty Columns Issue (Ext on Rails)

    - by Joe
    I'm playing with rewriting part of a web application in Rails + Ext. However, I'm having trouble getting an associated models' name to display in the grid view. I've been able to successfully convert several models and arrange the views nicely using tabs and Ext's layout helpers. However, I'm in the middle of setting up an association -- I've followed along with Jon Barket's tutorial on how to do this using Ext -- and I've made all the Rails and JS changes suggested (with appropriate name changes for my models,) the result being that the combo box is now being correctly populated with the names of the associated models, and changes are actually written correctly to database, BUT the data doesn't show up in the column, it's just empty. However, the correct data is there in the 'detail' view. Really just wondering if anyone else ran into this, or had any thoughts on what could be happening. Definitely willing to post code if requested; just note that (AFAIK) my changes follow the tutorial pretty closely. Thanks in advance! UPDATE: Alright, slight progress - kind of. I can get the associated model id # displaying properly -- just by modifying the column model slightly. But I can't get the virtual attribute displayed in the main table (in Jon's example it's country_name.) It still goes blank when I change the data source for that column from dataIndex: 'model[associated_model_id]' to dataIndex: 'virtual_attributes[associated_model_name]' ANOTHER UPDATE: Bump. Has NOBODY here tried integrating Ext with Rails?

    Read the article

  • Finding records when using has_many through associations

    - by winter sun
    I have two models, Worker and Project, and they are connected with has_many through association. I manage to find all the projects which are related to a specific worker by writing the following code: worker=Worker.find_by_id("some_id") worker.projects but I want the projects that I get to be only active projects (in the project model I have a status field) I tried to do something like worker.projects(:status_id=>'active') but it didn’t work for me. Can somebody tell me how I can do this?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >