Search Results

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

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

  • LINQ: Create persistable Associations in Code, Without Foreign Key

    - by Alex
    Hello, I know that I can create LINQ Associations without a Foreign Key. The problem is, I've been doing this by adding the [Association] attribute in the DBML file (same as through the designer), which will get erased again after I refresh my database (and reload the entire table structure). I know that there is the MyData.cs file (as part of the DBML) in which I can place my partial extensions etc. to domain objects (to persist even after I refresh the DBML), but I don't know how to create an association there?

    Read the article

  • Checking ActiveRecord Associations in RSpec.

    - by alokswain
    I am learning how to write test cases using Rspec. I have a simple Post Comments Scaffold where a Post can have many Comments. I am testing this using Rspec. How should i go about checking for Post :has_many :comments. Should I stub Post.comments method and then check this with by returning a mock object of array of comment objects? Is testing for AR associations really required ?

    Read the article

  • RoR - Associations into practise - forms (View)

    - by NicoJuicy
    I'm learning Ruby on Rails. I'm using some associations (has_many :through, ...) But i'm having some problems with it when i'm combining my views. How exactly do i combine these nested forms? Can i do this with partial forms and where do i have to write extra code for this? I have seen examples only use the "view" and others also edit the controller.... An example would be very nice :-)

    Read the article

  • Using Joins vs Entity associations

    - by shivesh
    I am learning Entity framework and linq-to-entities. It's possible to get cross values from multiple tables using JOINS (join keyword) or using the navigation fields ( associations) in which case the framework knows how to reference the cross data. My question is what to use when?

    Read the article

  • Ruby on Rails - Primary and Foreign key

    - by Eef
    Hey, I am creating a site in Ruby on Rails, I have two models a User model and a Transaction model. These models both belong to an account so they both have a field called account_id I am trying to setup a association between them like so: class User < ActiveRecord::Base belongs_to :account has_many :transactions end class Transaction < ActiveRecord::Base belongs_to :account belongs_to :user end I am using these associations like so: user = User.find(1) transactions = user.transactions At the moment the application is trying to find the transactions with the user_id, here is the SQL it generates: Mysql::Error: Unknown column 'transactions.user_id' in 'where clause': SELECT * FROM `transactions` WHERE (`transactions`.user_id = 1) This is incorrect as I would like the find the transactions via the account_id, I have tried setting the associations like so: class User < ActiveRecord::Base belongs_to :account has_many :transactions, :primary_key => :account_id, :class_name => "Transaction" end class Transaction < ActiveRecord::Base belongs_to :account belongs_to :user, :foreign_key => :account_id, :class_name => "User" end This almost achieves what I am looking to do and generates the following SQL: Mysql::Error: Unknown column 'transactions.user_id' in 'where clause': SELECT * FROM `transactions` WHERE (`transactions`.user_id = 104) The number 104 is the correct account_id but it is still trying to query the transaction table for a user_id field. Could someone give me some advice on how I setup the associations to query the transaction table for the account_id instead of the user_id resulting in a SQL query like so: SELECT * FROM `transactions` WHERE (`transactions`.account_id = 104) Cheers Eef

    Read the article

  • extension-base file associations

    - by Maurice Perry
    Hi there, I am using ubuntu 9.10, and I would like to associate thunderbird to all the files with the extension .eml. The problem is that is seems that ubuntu is attributing the mime type text/plain to these files, based on their content, which meens that if I set thunderbird as the default application for .eml files, all the other text files (.txt for instance) will be opened with thunderbird. Is it possible to add a rule to impose a mime type based on the file extension, regardless of its content?

    Read the article

  • Changing file extension associations

    - by ldigas
    What is the easiest way to permanently change association (program which opens etc.) for several file extensions at once? What I mean? Let's say you used TextEditorUncool up until now to open txt, dat, bat and abc files. Now you got TextEditorReallyCool and you wish if there was an application which on the left had a name of the program, and on the right a list of file extensions associated with it (which it, let's say, opens). Is there such a thing? Usually programs change this thing during installation (some even ask before), but in the case of portable programs one usually has to do it by hand, and for editors which open a gazillion of different file extensions, it gets tiresome really fast. All ideas welcomed !

    Read the article

  • File associations in windows 8

    - by soandos
    When I set a program to open a specific file type by default, it works (like Word 2013 for PDFs). However, when I change the default back to reader, I lose Word as an option that I can pick in the open with sub-menu. How can I get it to stick? Update: It seems that there is something special about word. Adding Notepad++ as the default and then changing it back seems to keep notepad++ on the sub-menu. Word version is 2013

    Read the article

  • Why are certain default application associations "locked"?

    - by H.B.
    Edit: As i now have three answers that do not answer the question: This question is not about getting the association to work again. I do not like fighting symptoms, i prefer cures. After associating my MP3 files with MPlayer using the Open with/Choose default program... dialogue i can no longer change that association using said dialogue, the Always use this [...] Checkbox is henceforth always greyed out (Control Panel > Default Programs > Associate a file type or protocol with a program does not let me change it either, it seems to just use the same dialogue anyway). That also happened for MP4s but not for MKVs for example, and if i associate my MP3s with other applications like VLC it does not get blocked. I would really like to know why that is and if i can avoid this beforehand (thankfully i know ways to fix it afterwards already). Edit: Another obervation: The blocking programs (i managed to block it with an association to Visual Studio as well) do not appear in the Recommended Programs of the open-with-dialogue (And the explorer said: "The current program is not recommended, but i won't let you change it, ha!"). Edit: A screenshot as requested: As you can see on the top left (if you know the icon of MPlayer), the file is currently associated with MPlayer. Edit: Ways to fix it (Note: This question is not about fixing it) Using the Default Programs Control Panel > Default Programs > Set Default Programs, select WMP, Choose defaults for this program, check .mp3 This should reassociate the files with WMP and you can create a new association in the explorer. Using the registry (As always, keep your hands off it unless you know what you are doing or if you are fine with accidentally breaking your system) HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Explorer > FileExts > .mp3 Here you could for example clean up the open-with-list, and the current default program seems to be saved here as well in the key UserChoice, there you can change the ProgId string to another application, you can associate it with WMP by entering WMP11.AssocFile.MP3 or just pick another application right away. You may need to mess with permissions on the key though, if you cannot change the ProgId value.

    Read the article

  • File associations not present in Microsoft Office 2010

    - by Babs Carter
    The error when trying to open MS Office is that there is no file association & another error when trying to open individual progs is - side bt side configuration is incorrect. The suite has been working perfectly until last week ( no significant changes to system ) I have tried downloading the VC++ & uninstalled & reinstalled twice, even deleted the registry entry for office 2010 before reinstall but have had no success. Any help would be greatly appreciated!

    Read the article

  • read/write_attribure on associations

    - by artemave
    read/write_attribute is a great way to enhance default accessors generated by ActiveRecord. Like this for example: def price read_attribute(:price) or "This item is priceless and you are by the way #{User.current.login}" end The same however does not seem to be working with associations. Demonstration: class Product < ActiveRecord::Base has_and_belongs_to_many :stores end Then >> a = Product.first => #<Product id: 1, name: "awesome product", created_at: "2010-05-07 12:11:00", updated_at: "2010-05-07 12:11:00"> >> a.stores => [#<Store id: 1, name: "ikea", created_at: "2010-05-07 12:11:28", updated_at: "2010-05-07 12:11:28">] >> a.read_attribute(:stores) => nil >> So, is there some sort of read/write_association? Or, if not, is there a reason not to have one?

    Read the article

  • accessing associations within GORM Events

    - by Don
    Hi, My Grails app has a User class and a Role class. The User class has an authorities property which holds the roles assigned to that user, e.g. class User { static hasMany = [authorities: Role] // This method is called automatically after a user is inserted def afterInsert() { this.authorities.size() } } If I create a user and assign them a role, a NullPointerException is thrown from the GORM event method afterInsert(), because authorities is null. If I comment out afterInsert() the user is saved correctly along with the assigned role. Is there some reason why I can't access associations from GORM event methods. Is is possible that this event is fired after the User row is inserted, but before the row is added to the User-Role join table? Thanks, Don

    Read the article

  • CakePHP Bake association problem

    - by Apu
    I have only two tables in my database with a one-to-many relationship between them (user hasMany messages) and am trying to get basic CRUD functionality going. Bake detects the associations correctly and specifies them correctly inside the model classes, but in controllers and views it looks like Cake doesn't know anything about those associations -- I don't even get a select tag for user_id when I go add a new message. Has anyone come across this problem before? What can I be doing wrong? Table structure appears to be fine: CREATE TABLE users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(255) NOT NULL, `password` varchar(255) NOT NULL, email varchar(255) NOT NULL, created datetime NOT NULL, modified datetime NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `messages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `content` varchar(255) NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    Read the article

  • Associations and the Grails webflow

    - by callie16
    Hi, it's my first time using webflows in Grails and I can't seem to solve this. I have 3 domain classes with associations that look something like this: class A { ... static hasMany = [ b : B ] ... } class B { ... static belongsTo = [ a : A ] static hasMany = [ c : C ] ... } class C { ... static belongsTo = [ b : B ] ... } Now, the GSP communicates with the controller via Javascript (due to my use of Dojo). When I try to remoteFunction a normal action, I can do something like this: def action1 = { def anId = params.id def currA = A.get(anId) def sample = currA.b?.c // I can get all the way to 'c' without any problems ... } However, I have a webflow and the contents of that action is in the webflow... It looks something like this: def someFlow = { ... someState { on("next") { def anId = params.id // this does NOT return a null value def currA = A.get(anId) // this does NOT return a null value def sample = currA.b // error already occurs here and I need to get 'c'! }.("somePage") ... } ... } In this case, it tells me that b doesn't exist... so I can't even get to 'c'. Any suggestions on what to do??? Thanks... getting real desperate...

    Read the article

  • Solr associations

    - by Tom
    Hi all, The last couple of days we are thinking of using Solr as our search engine of choice. Most of the features we need are out of the box or can be easily configured. There is however one feature that we absolutely need that seems to be well hidden (or missing) in Solr. I'll try to explain with an example. We have lots of documents that are actually businesses: <document> <name>Apache</name> <cat>1</cat> ... </document> <document> <name>McDonalds</name> <cat>2</cat> ... </document> In addition we have another xml file with all the categories and synonyms: <cat id=1> <name>software</name> <synonym>IT<synonym> </cat> <cat id=2> <name>fast food</name> <synonym>restaurant<synonym> </cat> We want to associate both businesses and categories so we can search using the name and/or synonyms of the category. But we do not want to merge these files at indexing time because we should update the categories (adding.remioving synonyms...) without indexing all the businesses again. Is there anything in Solr that does this kind of associations or do we need to develop some specific pieces? All feedback and suggestions are welcome. Thanks in advance, Tom

    Read the article

  • Not loading associations without proxies in NHibernate

    - by Alice
    I don't like the idea of proxy and lazy loading. I don't need that. I want pure POCO. And I want to control loading associations explicitly when I need. Here is entity public class Post { public long Id { get; set; } public long OwnerId { get; set; } public string Content { get; set; } public User Owner { get; set; } } and mapping <class name="Post"> <id name="Id" /> <property name="OwnerId" /> <property name="Content" /> <many-to-one name="Owner" column="OwnerId" /> </class> However if I specify lazy="false" in the mapping, Owner is always eagerly fetched. I can't remove many-to-one mapping because that also disables explicit loading or a query like from x in session.Query<Comment>() where x.Owner.Title == "hello" select x; I specified lazy="true" and set use_proxy_validator property to false. But that also eager loads Owner. Is there any way to load only Post entity?

    Read the article

  • ActiveRecord Validations for Models with has_many, belongs_to associations and STI

    - by keruilin
    I have four models: User Award Badge GameWeek The associations are as follows: User has many awards. Award belongs to user. Badge has many awards. Award belongs to badge. User has many game_weeks. GameWeek belongs to user. GameWeek has many awards. Award belongs to game_week. Thus, user_id, badge_id and game_week_id are foreign keys in awards table. Badge implements an STI model. Let's just say it has the following subclasses: BadgeA and BadgeB. Some rules to note: The game_week_id fk can be nil for BadgeA, but can't be nil for BadgeB. Here are my questions: For BadgeA, how do I write a validation that it can only be awarded one time? That is, the user can't have more than one -- ever. For BadgeB, how do I write a validation that it can only be awarded one time per game week?

    Read the article

  • Mixing has_one and has_and_belongs_to_many associations

    - by Thomas
    I'm trying to build a database of urls(links). I have a Category model that has and belongs to many Links. Here's the migration I ran: class CreateLinksCategories < ActiveRecord::Migration def self.up create_table :links_categories, :id => false do |t| t.references :link t.references :category end end def self.down drop_table :links_categories end end Here's the Link model: class Link < ActiveRecord::Base validates :path, :presence => true, :format => { :with => /^(#{URI::regexp(%w(http https))})$|^$/ } validates :name, :presence => true has_one :category end Here's the category model: class Category < ActiveRecord::Base has_and_belongs_to_many :links end And here's the error the console kicked back when I tried to associate the first link with the first category: >>link = Link.first => #<Link id: 1, path: "http://www.yahoo.com", created_at: "2011-01-10... >>category = Category.first => #<category id : 1, name: "News Site", created_at: "2011-01-11... >>link.category << category => ActiveRecord::StatementInvalid: SQLite3::Exception: no such column : categories.link_id: Are my associations wrong or am I missing something in the database? I expected it to find the links_categories table. Any help is appreciated.

    Read the article

  • Polymorphic NHibernate mappings

    - by Ben Aston
    I have an interface IUserLocation and a concrete type UserLocation. When I use ICriteria, specifying the interface IUserLocation, I want NHibernate to instantiate a collection of the concrete UserLocation type. I have created an HBM mapping file using the table per concrete type strategy (shown below). However, when I query NHibernate using ICriteria I get: NHibernate cannot instantiate abstract class or interface MyNamespace.IUserLocation Can anyone see why this is? (source code for the relevant bit of NHibernate here (I think)) My ICriteria: var filter = DetachedCriteria.For<IUserLocation>() .Add(Restrictions.Eq("UserId", userId)); return filter.GetExecutableCriteria(UoW.Session) .List<IUserLocation>(); My mapping file: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true"> <class xmlns="urn:nhibernate-mapping-2.2" name="MyNamespace.IUserLocation,MyAssembly" abstract="true" table="IUserLocations"> <composite-id> <key-property name="UserId" column="UserId" type="System.Guid"></key-property> <key-many-to-one name="Location" column="LocationId" class="MyNamespace.ILocation,MyAssembly"></key-many-to-one> </composite-id> <union-subclass table="UserLocations" name="MyNamespace2.UserLocation,MyAssembly2"> <property name="IsAdmin" /> </union-subclass> </class> </hibernate-mapping>

    Read the article

  • Polymorphic call

    - by harigm
    I am new to java, I have seen in the code at many places where my seniors have declared as List myList = new ArrayList(); (option1) Instead of ArrayList myList = new ArrayList(); (option2) Can you please tell me why people use Option1, is there any advantages? If we use option2, do we miss out any advantages or features?

    Read the article

  • Marshalling polymorphic objects in JAX-WS

    - by pkchukiss
    I'm creating a JAX-WS type webservice, with operations that return an object WebServiceReply. The class WebServiceReply itself contains a field of type Object. The individual operations would populate that field with a few different data-types, depending on the operation. Publishing the WSDL (I'm using Netbeans 6.7), and getting a ASP.NET application to retrieve and parse the WSDL was fine, but when I tried to call an operation, I would receive the following exception: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class [LDataObject.Patient; nor any of its super class is known to this context.] How do I mark the annotations in the DataObject.Patient class, as well as the WebServiceReply class to get it to work? I haven't been able to fine a definitive resource on marshalling based upon annotations within the target classes either, so it would be great if anybody could point me to that too. WebServiceReply.java @XmlRootElement(name="WebServiceReply") public class WebServiceReply { private Object returnedObject; private String returnedType; private String message; private String errorMessage; .......... // Getters and setters follow } DataObject.Patient.java @XmlRootElement(name="Patient") public class Patient { private int uid; private Date versionDateTime; private String name; private String identityNumber; private List<Address> addressList; private List<ContactNumber> contactNumberList; private List<Appointment> appointmentList; private List<Case> caseList; } Solution (Thanks to Gregory Mostizky for his answer) I edited the WebServiceReply class so that all the possible return objects extend from a new class ReturnValueBase, and added the annotations using @XmlSeeAlso to ReturnValueBase. JAXB worked properly after that! Nonetheless, I'm still learning about JAXB marshalling in JAX-WS, so it would be great if anyone can still post any tutorial on this. Gregory: you might want to add-on to your answer that the return objects need to sub-class from ReturnValueBase. Thanks a lot for your help! I had been going bonkers over this problem for so long!

    Read the article

  • Polymorphic association in reverse

    - by Erik
    Let's say that I have two models - one called Post and one other called Video. I then have a third model - Comment - that is polymorphically associated to to each of these models. I can then easily do post.comments and video.comments to find comments assosciated to records of these models. All easy so far. But what if I want to go the other way and I want to find ALL posts and videos that have been commented on and display these in a list sorted on the date that the comment was made? Is this possible? If it helps I'm working on Rails 3 beta.

    Read the article

  • Polymorphic Numerics on .Net and In C#

    - by Bent Rasmussen
    It's a real shame that in .Net there is no polymorphism for numbers, i.e. no INumeric interface that unifies the different kinds of numerical types such as bool, byte, uint, int, etc. In the extreme one would like a complete package of abstract algebra types. Joe Duffy has an article about the issue: http://www.bluebytesoftware.com/blog/CommentView,guid,14b37ade-3110-4596-9d6e-bacdcd75baa8.aspx How would you express this in C#, in order to retrofit it, without having influence over .Net or C#? I have one idea that involves first defining one or more abstract types (interfaces such as INumeric - or more abstract than that) and then defining structs that implement these and wrap types such as int while providing operations that return the new type (e.g. Integer32 : INumeric; where addition would be defined as public Integer32 Add(Integer32 other) { return Return(Value + other.Value); } I am somewhat afraid of the execution speed of this code but at least it is abstract. No operator overloading goodness... Any other ideas? .Net doesn't look like a viable long-term platform if it cannot have this kind of abstraction I think - and be efficient about it. Abstraction is reuse.

    Read the article

  • list of polymorphic objects

    - by LivingThing
    I have a particular scenario below. The code below should print 'say()' function of B and C class and print 'B says..' and 'C says...' but it doesn't .Any ideas.. I am learning polymorphism so also have commented few questions related to it on the lines of code below. class A { public: // A() {} virtual void say() { std::cout << "Said IT ! " << std::endl; } virtual ~A(); //why virtual destructor ? }; void methodCall() // does it matters if the inherited class from A is in this method { class B : public A{ public: // virtual ~B(); //significance of virtual destructor in 'child' class virtual void say () // does the overrided method also has to be have the keyword 'virtual' { cout << "B Sayssss.... " << endl; } }; class C : public A{ public: //virtual ~C(); virtual void say () { cout << "C Says " << endl; } }; list<A> listOfAs; list<A>::iterator it; # 1st scenario B bObj; C cObj; A *aB = &bObj; A *aC = &cObj; # 2nd scenario // A aA; // B *Ba = &aA; // C *Ca = &aA; // I am declaring the objects as in 1st scenario but how about 2nd scenario, is this suppose to work too? listOfAs.insert(it,*aB); listOfAs.insert(it,*aC); for (it=listOfAs.begin(); it!=listOfAs.end(); it++) { cout << *it.say() << endl; } } int main() { methodCall(); retrun 0; }

    Read the article

  • polymorphic hql

    - by Berryl
    I have a base type where "business id" must be unique for a given subclass, but it is possible for there to be different subclasses with the same business id. If there is a base type with a requested id but of the wrong subclass I want to return null, using a named query. The code below does this, but I am wondering if I can avoid the try/catch with a better HQL. Can I? Cheers, Berryl current hql <query name="FindActivitySubjectByBusinessId"> <![CDATA[ from ActivitySubject act where act.BusinessId = :businessId ]]> </query> current fetch code public ActivitySubject FindByBusinessId<T>(string businessId) where T : ActivitySubject { Check.RequireStringValue(businessId, "businessId"); try { return _session.GetNamedQuery("FindActivitySubjectByBusinessId") .SetString("businessId", businessId) .UniqueResult<T>(); } catch (InvalidCastException e) { // an Activity Subject was found with the requested id but the wrong type return null; } }

    Read the article

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