w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
How to Order Entities (ManyToOne association) when using DoctrineORMModuleFormElementEntitySelect annotation
add to the entity above the property @ORMOrderBy({"name" = "ASC"}) more info here EDIT: ofcourse name and ASC need to be replaced by the values of your liking/needing

Categories : PHP

Saving one or more entities that have a non-nullable association with an unsaved transient entity
Saving the Student causes both the Feedback and the Suggestions entities to be saved by some order which is unrelated to the fact that Feedback is dependent on Suggestions. Try saving the Suggestions entity first and only then the Student (which will cause the Feedback to also be saved, but this time after Suggestions), like that: dao.save(feed); dao.save(user); You might encounter additional mal-ordered save operations so you'll just have to save them separately accordingly.

Categories : Hibernate

Validate Zend Form with empty mapped association between entities
I believe the trouble is in your Orders entity, try to change: @ORMOneToOne(targetEntity="AdminEntityOrdersStatus") to this: @ORMManyToOne(targetEntity="AdminEntityOrdersStatus") I would also remove "array('name' => 'Null')," from filters from status inputFilter since required = FALSE

Categories : Forms

Hibernate criteria with 2 entities table and 1 association table
I tried to write a criteria query with your indications, but it's not easy because you tell that A and B tables have a int ID, but then you put Strings in your rows ("A1", "B1"...). I supposed that your id is a String instead of an int. You should have something like this: List<A> listOfA = new ArrayList<A>(); Criteria criteria = session.createCriteria(B.class, "b"); criteria.add(Restrictions.eq("b.id", "B1")); List<B> listOfBs = criteria.list(); for (B b : listOfBs) { listOfA.addAll(b.getA()); } If you have a name property in B class, you would have to modify the restriction: criteria.add(Restrictions.eq("b.name", "B1")); I hope this code can help you solve your problem.

Categories : Java

How do I test a has_many :through association that also has a validates_presence_of validation on the association with Factory Girl in Rails?
The error message says expected ..... to be valid, but got errors: Client can't be blank work = FactoryGirl.build(:work) # this returns an unsaved object By using build you haven't saved the object. The object is nil. If an object is nil it is blank You want to save the object on creation like this work = FactoryGirl.create(:work) # this returns a saved object Now work.should be_valid should pass UPDATE: I didn't look closely enough at your `factories.rb' factory :work do name "Client Website" client date 1.day.ago description "A great new website for the client." image "/image.jpg" service "Web" featured true end your client attribute in the work factory is literally blank. This wont pass validation and won

Categories : Ruby On Rails

Comments system : Hstore with normal association VS simple attributes with polymorfic association
I would go with something like https://github.com/jackdempsey/acts_as_commentable. I'm not sure if you can query within hstore, but in general, keeping the Comment as a an ActiveRecord model might be more convenient. (think about associations, querying and all the other Activerecord stuff you get as opposed to using HStore.)

Categories : Ruby On Rails

When building a json api for a model with a belongs_to association, the whitelisted attributes of that association are ignored
Taken from this fine gentleman from the issue queue of ActiveModelSerializer's github page: https://github.com/rails-api/active_model_serializers/issues/371#issuecomment-22363620 class UserSerializer < ActiveModel::Serializer attributes :id, :email, :name_n, :first_name, :last_name has_one :role, serializer: RoleSerializer end So, even though there is a User belongs_to :role association in the controller, using has_one association utilizes the ActiveModel Serializer and gives me only the attributes I want.

Categories : Ruby On Rails

How one to many relationship gets persisted in JPA if i have thousands of related entities already in data base and i add new entities in collection
If you want to add new instances to a relation between two already existent entities (a one to many in this case) then you must first fetch from the database the entity that contains the collection; in your case myEntity. So, when you load that entity you are bringing it to memory. If you had defined the relation between those two as EAGER then all the related entities (the ones in the collection) will be fetched as well at the same time than the parent one. If you, otherwise, had defined the relation as LAZY then the related entities will be loaded when you access the collection (in other, words, when you invoke the getter getXXX method for that collection). This happens that way because JPA implementations (now I'm thinking on Hibernate) return proxies of the entities instead of actual

Categories : Java

Minecraft Bukkit - How can I use item entities and falling block entities as projectiles?
You could replace a bow's arrow projectile with your own custom projectile, such as an item entity. You would catch the ProjectileLaunchEvent and do something like this: Entity arrow = event.getEntity(); Vector velocity = arrow.getVelocity(); Item item = arrow.getWorld().dropItem(arrow.getLocation(), ItemStack); item.setVelocity(velocity); If you wanted to deal damage, you would have to constantly track it's location with schedulers, check if it intersects a player, and deal the appropriate amount of damage. Or, if you want a simpler approach, just see if a player picks up the item, take the item out of their hands, and deal damage.

Categories : Java

linq to entities if filter parameter is null then select all entities?
Normally you do it this way: IQueryable<Brief> briefs = NeptuneUnitOfWork.Briefs.Where(b => b.ID == briefID); if (competitorID != null) { competitors = briefs.Select(b => b.BriefCompetitors.Where(b=>b.ID == competitorID)); } else { competitors = briefs.Select(b => b.BriefCompetitors); } Technically you could leave the problem to the SQL Server: // Note the || clause competitors = briefs.Where(b => b.ID == briefID) .Select(b => b.BriefCompetitors.Where(b=>b.ID == competitorID || competitorID == null));

Categories : Linq

Linq to Entities - Get list of all unique related entities
If you want all the unique tag names you can do: places.SelectMany(x => x.Tags).Select(x => x.Name).Distinct() if the two instances of the same tag are the same object then you can just do places.SelectMany(x => x.Tags).Distinct(); if they are different objects then you can do places.SelectMany(x => x.Tags).GroupBy(x => x.TagId).Select(g => g.First()); UPDATE after new comment. Add ToList() to then end to convert the result into a list. places.SelectMany(x => x.Tags).Select(x => x.Name).Distinct().ToList(); places.SelectMany(x => x.Tags).Distinct().ToList(); places.SelectMany(x => x.Tags).GroupBy(x => x.TagId).Select(g => g.First()).ToList();

Categories : Asp Net Mvc

self referential association with polymorphic association
Solved using has_one instead of belongs_to on User.rb has_one :default_address, class_name: "Address", as: :addressable, dependent: :destroy accepts_nested_attributes_for :default_address

Categories : Ruby On Rails

Is it Okay to have Entities in Core Data with no relation with any other entities?
If its logged in user information it should probably be in the keychain. You can have an entity with no relationships, there's nothing to prevent it, but accessing those details will now require that you open the model store file. If you only need them when the store is open then not too much of a problem. The process of extracting the entity instance is still a fetch request so constitutes more code than the NSUserDefaults option. There's no hard and fast rule, each area of data storage is more useful for access at different times and you should expect to use each of them in your app. You should also consider how long the data should be retained and how many copies you need (now, and potentially in the future). Generally, for user account details I'd hold them outside the Core Data mod

Categories : IOS

One to Many relationship between two Entities when both entities has composite primary key
The way to do this is to define two @Embeddable entities to represent the composite keys for A and B. BKey is identical to AKey except that it adds "a6" property. AKey Class: @Embeddable public class AKey implements Serializable { private String a1; private String a2; private String a3; private String a4; private String a5; public AKey() { } public AKey(String a1, String a2, String a3, String a4, String a5) { this.a1 = a1; this.a2 = a2; this.a3 = a3; this.a4 = a4; this.a5 = a5; } ... // getters & setters } Then you define your A class to use the Embeddable composite key class as the @IdClass but still use the composite key elements as properties. You would do the same thing for the B class (using B

Categories : Hibernate

Mapping EF entities to POCO business entities
Yes, it is possible to use AutoMapper. But I suggest you to use Code First approach - persist domain entities directly. You can write Entity Framework mappings manually or generate them with Reverse Engineer Code First. That will remove unnecessary complexity from your system.

Categories : C#

Entities within Entities in Core Data - Xcode
This is the correct way to do it. You can't "embed" an entity inside an entity. If you want to have a deck entity that can have multiple instances of a vocabulary entity attached to it, you need to create separate entities for deck and vocabulary, and add a to-many relationship from your deck entity to your vocabulary entity, and a to-one relationship from your vocabulary entity back to your deck entity. Here's a basic pair of entities in a Core Data model to demonstrate this: As you can see in the image, the Deck entity has a to-many relationship named vocabularies to the Vocabulary entity, with an inverse relationship deck. The vocabularies relationship in the Deck entity is configured like so: and the deck relationship in the Vocabulary entity is configured like this: Note t

Categories : Iphone

ORM Entities vs. Domain Entities under Entity Framework 6.0
I agree with the general idea of these posts. An ORM class model is part of a data access layer first and foremost (even if it consists of so-called POCOs). If any conflict of interests arises between persistence and business logic (or any other concern), decisions should always be made in favor of persistence. However, as software developers we always have to balance between purism and pragmatism. Whether or not to use the persistence model as a domain model depends on a number of factors: The size/coherence of the development team. When the whole team knows that properties can be public just because of ORM requirements, but should not be set all over the place, it may not be a big deal. If everybody knows (and obeys) that an ID property is not to be used in business logic, having IDs

Categories : Entity Framework

Search by properties of two Entities (fetch from two Entities)
Issue solved. At the stage of preloading data from JSON file into Core Data I am define getters for properties (prefetching data from entity)in B and setting entity properties of A equal to returned results of this getters (all this in NSManagedObject subclasses inherited from entities). So after that I am able to fetch all what I need using this getters through appropriate properties.

Categories : IOS

Get Difference between Following Entities Linq to Entities
Came up with sth like this private bool LessThan7DaysApart(DateTime d1, DateTime d2) { return (d1 - d2).Duration() < new TimeSpan(7, 0, 0, 0); } private void Match() { List<User> listfortype0 = users.Where(u => u.UserType == 0).ToList(); List<User> listfortype1 = users.Where(u => u.UserType == 1).ToList(); foreach (User u in listfortype0) { List<User> tmp = listfortype1.Where(u2 => LessThan7DaysApart(u2.SignUpDate, u2.SignUpDate)).ToList(); if (tmp.Count > 0) { List<User> matchedusers = new List<User> { u, tmp[0] }; listfortype1.Remove(t

Categories : C#

Filtering Association By Another Association
I think you want: class User has_many :friendships, :class_name => "FriendStatusDescriptor", :foreign_key => 'friendship_id' If you want to filter visible and non-visible friendships by separete you can add scopes to Friendship model: class Friendship scope :visible, -> { joins(:status).where("friend_status_descriptors.hide = ?", false) } Then apply that scope: user.friendships.visible

Categories : Ruby On Rails

Request factory - load referenced entities of referenced entities
This should work provided there is a getUser() field in the comment interface: ArticleRequest request = requestFactory.articleRequest(); request.findArticleById(1).with("comments.user");

Categories : Java

Many to many association
There is nothing wrong with defining an intermediate model for the relationship. That way you can store extra information on the intermediate model (Membership), like when the person joined the group, or if the membership is still valid. However, most of the time you don't need the extra information and only want to store which person is member of which group. In those cases, you could just use a simple ManyToManyField. Django makes it very easy to work with those fields, so you can do group.members.add(user) and group.members.delete(user), compare that to: Membership.objects.create(user=user, group=group) Membership.objects.get(user=user, group=group).delete() Disclaimer: pseudo-code, might not actually work You can still use ManyToManyField with an intermediate model, this allows for

Categories : Django

FactoryGirl ID association
You may try : FactoryGirl.define do factory :connection do from_id 1 to_id 4 end end FactoryGirl.define do factory :leg do association :connection, factory: :connection from_id 1 to_id 2 end end then FactoryGirl.create(:leg).connection_id # => 1 or whatever your connection_id is or (if you want to reuse the connection instance elsewhere) : connection = FactoryGirl.create(:connection) FactoryGirl.create(:leg, :connection=> connection).connection_id # => 1 or whatever your connection_id is

Categories : Ruby On Rails

Where does association extension sit in
Delayed Job's delay function checks for whether the object responds to the method that is queued and would return a NoMethodError because the function is not defined for the Items class. The ways extensions work is by adding a module to the owner class of the proxy_association, in this case you will be able to access the function from Bundle::BundleItemsAssociationExtension.instance_methods. Therefore, the delay method won't be able to access foo method even if you pass an association object. I would suggest moving the method to the Items class and then calling delayed job on it.

Categories : Ruby On Rails

How set association in windows 8?
In Windows 8 there is only one way to do this. You should add your app to Defaults Applications. Then use Default Programs to ask an user to set associations. Unsure the old way with registry editing now is not availabled. In Windows 8 was added Hash variable to UserChoice registry key. It is unique for user and app. If it is wrong YourAppName is not be started by default but Windows 8 ask to choose application. Short instruction how to add app to Default Programs. Full guide there http://msdn.microsoft.com/en-us/library/windows/desktop/cc144154%28v=vs.85%29.aspx Add to registry key: "HKLMSoftwareRegisteredApplications" name: "YourAppName" value: "SofwareYouCompanyYourAppNameCapabilities" key: "HKLMSofwareYouCompanyYourAppNameCapabilities" name: "ApplicationDescription" value: "just a de

Categories : C++

Launch App through SMS (URI-Association)
It's working for me fine. Just put the raw URI in the SMS. myapp:param=test This should show as a link in the SMS which when clicked will launch the app or cause the Store app to open. Of course on a phone which doesn't support the URI this won't work. An alternative would be to send by SMS a link to a website which then presents a app-launch link on compatible phones. (This is what Spotify does for example).

Categories : C#

What is unidirectional many-to-many association?
Unidirectional means that, for example, A has a reference to Bs, but not the other way around. many to many means bidirectional No. The many to many concept is for database table mapping. Hibernate uses it (and other x-to-x) to generate the proper database table schema. The x-directional concept is for java objects.

Categories : Java

How to set up a three model association?
I think you can set it up more simply - like this: Audio.rb has_many :PT has_many :songs Partner.rb belongs_to :AT Song.rb belongs_to :AT You don't need to worry about migrations, just put that code into the models and you're set. To access, for example, a song with ID 33, you could use audio.songs.find(33)

Categories : Ruby On Rails

Association ExtJs MVC 4.2
Well, I took a step and got the solution for this. the raw parameter actually has the raw JSON payload. In the controller part I have handled it via a select event. onSelectIssueShowComments : function(selection,record, index, eOpts) { this.getComments().setRecord(record.raw); } I the view part tpl : [ '<p>Previous Comments: ', '<tpl for="comments">', '<p>{#}. {description} {commentDate}</p>', '</tpl></p>' ], setRecord : function(record) {//this record here is record.raw this.record = record; if (record) { this.update(record); } else { this.update(' '); } } So it displays the array of comments in a Panel.

Categories : Extjs

One-to-one DataMapper association
There are different ways you could do this. Here's one option: class User include DataMapper::Resource property :id, Serial # Other properties... has 1, :referee, :required => false has 1, :player, :required => false end class Referee include DataMapper::Resource # DON'T include "property :id, Serial" here # Other properties... belongs_to :user, :key => true end class Player include DataMapper::Resource # DON'T include "property :id, Serial" here # Other properties... belongs_to :user, :key => true end Act on the referee/player models like: u = User.create(...) u.referee = Referee.create(...) u.player = Player.create(...) u.player.kick_ball() # or whatever you want to call u.player.homeruns u.referee.flag_play() # or whatever. See if this works

Categories : Ruby

Rails association
class Post has_one :photo, as: :photoable end class Project has_one :photo, as: :photoable end class Photo belongs_to :photoable, polymorphic: true end http://guides.rubyonrails.org/association_basics.html (check out section 2.9 on polymorphic associations)

Categories : Ruby On Rails

Association dilemma
You have to use nested attributes for this. Check this http://currentricity.wordpress.com/2011/09/04/the-definitive-guide-to-accepts_nested_attributes_for-a-model-in-rails-3/. Basically what you need is: # collection model accepts_nested_attributes_for :pins # view, see also nested_form in github f.fields_for :pins

Categories : Ruby On Rails

How to get an Id value from association rails
First you need to remove the attribute disabled from your field, a disabled field isn't sended by your form (look at Disabled form fields not submitting data). And, your user_id should be placed in something like params[:note][:user_id], take a look at server log and search for user_id right after you send a POST to server, there be something like: Started POST "/note" for ::1 at 2013-07-18 15:22:34 +0000 Processing by NoteController#create as */* Parameters: {"note"=>{..., "user_id"=>"1", ...}}

Categories : Ruby On Rails

Persist association symfony2
There are some errors in your ORM annotation : both $coach and $players have a targetEntity of User and the same inveredBy attribute. inversedBy should be the attribute of User class that is the other side of the many to many association, for exemple repectively $coachedTeams and $playInTeams. Your addTeam code remove previous associations because you call $player->setPlayers(array($entity)): it replace the old collection of associations by the new one. You should call $player->addPlayer($entity) instead, to add a new object to the existing collection. If you generated your entities with php app/console doctrine:generate:entities, you should not have method setPlayers() but addPlayer() and removePlayer(). Please also note that association with Doctrine are stored as DoctrineCommonCol

Categories : Symfony2

rails polymorphic many-to-many association
You could do the following Category.first.categorizables.where(categorizable_type: 'Company') that would select all the Companies associated with Category using your relationship schema. Also read some about has_many :through association because I think you don't quite get it http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association

Categories : Ruby On Rails

rails_admin has_and_belongs_to_many association
I had downgraded from rails_admin 0.4.9 to 0.4.1 and problem solves. You can track progress of solution here: https://github.com/sferik/rails_admin/issues/1737

Categories : Ruby On Rails

Many to one association converting to postres
You have defined the house_id column in the table mates as a character type, and it should be an integer. Some RDBMS are forgiving of this, but PostgreSQL is not. You should correct this with a migration, and check the database schema for other such errors as well. Because it's possible for a character column to contain non-numeric values, when migrating you'll have to issue the SQL statement: alter table mates alter column house_id type integer using cast(house_id as integer);

Categories : Ruby On Rails

Model Association using rails3 way
Assuming that your join table is called product_categories, you could just add a sort column to the join table. Then you can set your has_many through association like so: has_many :product_categories has_many :categories, through: :product_categories, order: 'product_categories.sort' Another option that may work would be to add a default scope to the ProductCategory model: default_scope order(:sort)

Categories : Ruby On Rails

criteria for @OneToMany association
Criteria mastersCriteria = getSession().createCriteria(Student.class, "student"); mastersCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); mastersCriteria.createAlias("student.resume", "resume"); mastersCriteria.createAlias("resume.masters","masters"); if (degreeslist.size() == 1) { mastersCriteria.add(Restrictions.eq("masters.degreeName", degreeslist.get(0))); } else { mastersCriteria.add(Restrictions.in("masters.degreeName", degreeslist)); } List<Student> students = mastersCriteria.list();

Categories : Java

How can I dry many to many association assignments in rspec?
This gem could do the thing: https://github.com/thoughtbot/factory_girl factory :label do name "label example" user end factory :user do name "John Doe" after(:create) do |user| FactoryGirl.create_list(:label, 1, user: user) end end factory :issue do name 'issue' after(:create) do |issue| issue.users = FactoryGirl.create_list(:user, 1) end end And after that you could do such things: issue = FactoryGirl.create(:issue) issue.users # returns array with 1 user issue.users.first.label # returns array with one label

Categories : Ruby On Rails



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.