relationships

CakePHP select default value in SELECT input

旧时模样 提交于 2019-11-29 11:34:11
问题 Using CakePHP: I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper. The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tree it's being added to: For example, calling example.com/leaf/add/5 would bring up the interface to add a new Leaf to Tree #5. The dropdown box for Leaf.tree_id

Cross-Store weak relationship with Fetched Properties?

北城以北 提交于 2019-11-29 10:16:35
问题 I would like to separate my reference data from my user data in my Core Data model to simplify future updates of my app (and because, I plan to store the database on the cloud and there is no need to store reference data on the cloud as this is part of my application). Therefore, I've been looking for a while for a way to code a cross-store relationship using fetched properties. I have not found any example implementations of this. I have a Core Data model using 2 configurations : data model

Laravel Relationships

元气小坏坏 提交于 2019-11-29 06:07:38
I've been looking over relationships in Laravel 4 in the documentation and I'm trying to work out the following. I have a table in my database called 'events'. This table has various fields that mainly contain ID's that relate to other tables. For example, I have a 'courses' table. The events table contains a field called 'course_id' which relates to the ID of the 'id' field in the courses table. So basically, I'm after some advice on how you go about relating the two (belongsTo()?) and then passing the connected data to the view. Here is where I am at so far http://paste.laravel.com/pf3 . I

How to GROUP and SUM a pivot table column in Eloquent relationship?

二次信任 提交于 2019-11-28 23:51:08
In Laravel 4; I have model Project and Part , they have a many-to-many relationship with a pivot table project_part . The pivot table has a column count which contains the number of a part ID used on a project, e.g.: id project_id part_id count 24 6 230 3 Here the project_id 6, is using 3 pieces of part_id 230. One part may be listed multiple times for the same project, e.g.: id project_id part_id count 24 6 230 3 92 6 230 1 When I show a parts list for my project I do not want to show part_id twice, so i group the results. My Projects model has this: public function parts() { return $this-

How to delete/create databases in Neo4j?

这一生的挚爱 提交于 2019-11-28 15:24:24
Is it possible to create/delete different databases in the graph database Neo4j like in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph to get a clean setup for tests, e.g., using shell commands similar to rmrel or rm ? Peter Neubauer You can just remove the entire graph directory with rm -rf , because Neo4j is not storing anything outside that: rm -rf data/* Also, you can of course iterate through all nodes and delete their relationships and the nodes themselves, but that might be too costly just for testing ... even more simple command to delete all nodes

How to setup conditional relationship on Eloquent

人盡茶涼 提交于 2019-11-28 10:17:19
I have this (simplified) table structure: users - id - type (institutions or agents) institutions_profile - id - user_id - name agents_profile - id - user_id - name And I need to create a profile relationship on the Users model, but the following doesn't work: class User extends Model { public function profile() { if ($this->$type === 'agents') return $this->hasOne('AgentProfile'); else return $this->hasOne('InstitutionProfile'); } } How could I achieve something like that? Lets take a different approach in solving your problem. First lets setup relationship for the various models respectively

How to GROUP and SUM a pivot table column in Eloquent relationship?

醉酒当歌 提交于 2019-11-27 15:18:57
问题 In Laravel 4; I have model Project and Part , they have a many-to-many relationship with a pivot table project_part . The pivot table has a column count which contains the number of a part ID used on a project, e.g.: id project_id part_id count 24 6 230 3 Here the project_id 6, is using 3 pieces of part_id 230. One part may be listed multiple times for the same project, e.g.: id project_id part_id count 24 6 230 3 92 6 230 1 When I show a parts list for my project I do not want to show part

Ruby on rails - Reference the same model twice?

你。 提交于 2019-11-27 10:29:43
Is it possible to set up a double relationship in activerecord models via the generate scaffold command? For example, if I had a User model and a PrivateMessage model, the pm table would need to keep track of both the sender and recipient . Obviously, for a single relationship I would just do this: ruby script/generate scaffold pm title:string content:string user:references Is there a similar way to set up two relations? Also, is there anyway to set up aliases for the relations? So rather than saying: @message.user You can use something like: @message.sender or @message.recipient Any advice

Laravel merge relationships

橙三吉。 提交于 2019-11-27 09:15:45
Is there a way to merge 2 relationships in laravel? this is the way it's setup now, but Is there a way I could return both merged? public function CompetitionsHome() { return $this->HasMany( 'Competition', 'home_team_id' ); } public function CompetitionsGuest() { return $this->HasMany( 'Competition', 'guest_team_id' ); } public function Competitions() { // return both CompetitionsHome & CompetitionsGuest } Try out getter method for property which returns merged collections returned from relations. public function getCompetitionsAttribute($value) { // There two calls return collections // as

How to delete/create databases in Neo4j?

大城市里の小女人 提交于 2019-11-27 09:11:57
问题 Is it possible to create/delete different databases in the graph database Neo4j like in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph to get a clean setup for tests, e.g., using shell commands similar to rmrel or rm ? 回答1: You can just remove the entire graph directory with rm -rf , because Neo4j is not storing anything outside that: rm -rf data/* Also, you can of course iterate through all nodes and delete their relationships and the nodes themselves,