relationship

Laravel Eloquent Self Join Parent Child

不问归期 提交于 2019-12-12 03:49:30
问题 Laravel Eloquent Self Join Parent Child Relationship class Product_category extends Model { // protected $table='PRODUCT_CATEGORIES'; public $timestamps = false; public function getParentCategory() { return $this->hasOne(self::class, 'id', 'parent_id'); }. public function getChildCategories(){ return $this->hasMany(self::class, 'parent_id','id'); } I am able to retrieve all child records of table by making use of getChildeCategories but not able to retrieve Parent of particular category. It

Querying Relations Laravel Eloquent ORM

心不动则不痛 提交于 2019-12-12 03:19:50
问题 I have an issue understanding pretty well the Relationships, let's go to the point I have 3 tables, with its proper models receipt - id - date items_sold - id - receipt_id - item_id items - id - name The problem I have is that receipt "has many" items through items_sold, but I can't use "hasManyThrough" because eloquent use the wrong "id" of "items_sold", even if I put manually the keys class Receipt extends Eloquent { public function items() { return $this->hasManyThrough('Items', 'ItemsSold

Category relationship in laravel Undefined property: stdClass::

谁说胖子不能爱 提交于 2019-12-12 03:08:57
问题 Hi i'm working on a laravel training project . i'm having an issue with models and relationships when i'm trying to get the each product category name . Here is my Product Model <?php namespace App; use Illuminate\Database\Eloquent\Model; class Product extends Model { public function category() { return $this->belongsTo('App\Category'); } } and my Category model <?php namespace App; use Illuminate\Database\Eloquent\Model; class Category extends Model { protected $table = 'categories'; public

Can't retrieve a one to many relationship in Laravel 4

帅比萌擦擦* 提交于 2019-12-12 02:28:09
问题 I'm trying to get to a ProfileType through my User model, i.e. $user->profile->profiletype; I'm not able to retrieve an object, however. Basically, User hasOne Profile, and Profile belongsTo User and ProfileType. ProfileType hasMany Profile. My table names are users, profiles and profile_types. models/User.php use Cartalyst\Sentry\Users\Eloquent\User as SentryUserModel; class User extends SentryUserModel { /** * Indicates if the model should soft delete. * * @var bool */ protected $softDelete

One to many relationship count - difference in accessing relationship

流过昼夜 提交于 2019-12-12 01:55:37
问题 I have one to many relation - Entry can have many Visits . In my Entry model I have the following methods: public function visits() { return $this->hasMany ('Visit', 'entry_id','id'); } public function visitsCount() { return $this->hasMany('Visit', 'entry_id','id') ->selectRaw('SUM(number) as count') ->groupBy('entry_id'); } In Blade I can get number of visits for my entry using: {{$entry->visits()->count() }} or {{ $entry->visitsCount()->first()->count }} If I want to create accessor for

Liferay and relationships in it

﹥>﹥吖頭↗ 提交于 2019-12-12 01:46:00
问题 I have a portlet, which can add/update/delete books and add authors. Moreover, you can choose existing authors when you try to add book. And now I need to show how many books were written by each author in "author" table. How can I do it? Im a newbie in liferay and I even have no idea. It's my service.xml <entity name="Book" local-service="true" remote-service="true" cache-enabled="false"> <column name="bookId" type="long" primary="true" /> <column name="bookName" type="String" /> <column

Kohana many-to-many relationship “has many - through”

落花浮王杯 提交于 2019-12-12 01:43:41
问题 I'm using kohana v3.3, and i would like to know if there is a possibility to get/save another data in the pivot table or not ? let's take the Auth example : So we have 3 tables (roles, users, roles_users) and i added another column "date" on the pivot table Tables : CREATE TABLE IF NOT EXISTS roles ( id int(11) UNSIGNED NOT NULL AUTO_INCREMENT, name varchar(32) NOT NULL, description varchar(255) NOT NULL, PRIMARY KEY ( id ), UNIQUE KEY uniq_name ( name ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CoreData returning set with empty objects

江枫思渺然 提交于 2019-12-11 19:52:28
问题 I've been looking into this issue for the last day, so I think it's time to ask the question. I created a one-to-many self referencing relation in CoreData to store contacts and group these contacts. Contacts that haven't got a parent actually hold the "section name" of its children. Section name (object without parent) ------------------------------------- Contact 1 Contact 2 Code to save the objects (simplified): //Create Section section = [NSEntityDescription

SQL relationships and best practices

孤街浪徒 提交于 2019-12-11 19:07:23
问题 If I have a User table and a Roles table. What is the usual practice/pattern for adding the relationship ? Do I create an extra column in the User table for the RoleID or do people usually create a Relationships table like so: Relationships Table RelationshipID | UserID | RoleID |... any other relations a user might have for the last bit, as a user you might create an endless amount of different types of things that all need to be related to you... do you instead add the relationship to each

Relation one to one in sf1.4/propel

拟墨画扇 提交于 2019-12-11 19:05:09
问题 i have installed sfGuardPlugin and created this model: propel: sf_guard_user_profile: _attributes: { phpName: sfGuardUserProfile } id: ~ user_id: { type: integer, foreignTable: sf_guard_user, foreignReference: id, required: true, onDelete: cascade } name: varchar(50) As it is written here, http://www.propelorm.org/wiki/Documentation/1.4/Relationships (see "One-to-one relationships"), It is supposed symfony generates the function sfGuardUser->getSfGuardUserProfile() and sfGuardUserProfile-