Skip to main content

Questions tagged [has-one]

The tag has no usage guidance.

has-one
1 vote
0 answers
91 views

Laravel hasOne with two matching fields

I need to establish a hasOne relationship that matches two fields simultaneously. Here's my users table: ID user conc name 1 JDoe ABC John Doe 2 JDoe ZXC John Doe And here's my membership table: ...
mps's user avatar
  • 455
0 votes
2 answers
85 views

has_one from model attributes instead of foreign key

I would like to have a has_one relation based on my Product's attributes rather than its id. class Pricing belongs_to :type belongs_to :brand validates :type_id, uniqueness: { scope: :brand_id } ...
Daniel Costa's user avatar
0 votes
1 answer
58 views

Laravel Eloquent Query WhereHas

I have the following code for reference //MODEL_A public function latest_B() { return $this->hasOne(B::class)->latest(); } public function Bs() { return $this->hasMany(B::class); } //...
jeesoon's user avatar
  • 437
0 votes
3 answers
47 views

I am getting an error when trying to access and return hasOne from the controller to the frontend

Response::setContent(): Argument #1 ($content) must be of type ?string I am getting the above error, when trying to access and return hasOne from the controller to the front end. I have created two ...
sajid ahamed's user avatar
0 votes
0 answers
410 views

Laravel hasOne()->orderBy() vs hasOne()->ofMany()

One bit of "magic" in the Laravel codebase is here in HasOneOrMany.php where if the underlying query behind a hasOne relationship technically fetches multiple rows, it will just return the ...
Erich's user avatar
  • 2,588
0 votes
0 answers
120 views

Cakephp 4 custom hasOne Associaton Condition

I have those two tables: Addresses: id | member_id | label | ... | start | end | ... and Members: id | firstname | ... | created | modified Every member has many addresses during his life, and I ...
molarum's user avatar
  • 13
0 votes
1 answer
63 views

Rails SQL sort by inner has_one association field

Every User has one active account. How do i use sql to sort all Users by the updated_at field in active_account? class User < ApplicationRecord has_one :active_account, -> { order('created_at ...
Hannah__'s user avatar
-1 votes
1 answer
1k views

rails 7 ActionController::UnknownFormat in ManagersController#destroy Problem with has_one association destroy action

I have a simple rails app where a Project has_one Manager. All actions works as expected except for the @manager.destroy action. The record is deleted successfully from the database but I get an ...
user1791061's user avatar
1 vote
0 answers
415 views

EF Core 6: Optional HasOne Relationship

I have a situation similar to Entity Framework 6 define a REALLY optional foreign key in which I would like to configure a HasOne relationship when the foreign key may or may not exist in the target ...
bpoxy's user avatar
  • 21
0 votes
1 answer
573 views

HasOne showing either "null" or "Undefined property: Illuminate\\Database\\Eloquent\\Relations\\HasOne"

I'm trying to use hasOne to return a single value within my data set, however I can't seem to return the single column as a value without returning the full object. What the object looks like when ...
YaBCK's user avatar
  • 2,979
0 votes
1 answer
93 views

CanCanCan gem in Rails app: Preventing guests from accessing a specific model does not work

In a Rails app which uses JSONAPI::Resources and CanCanCan, I have a Caption model (has_one :video) and a Video model (has_many :captions). I want to allow guests to only access those captions which ...
Pida's user avatar
  • 978
0 votes
2 answers
127 views

Ruby finding all objects where has_one relation is true and is in array

I am currently trying to implement a has_one relationship where you are able to search through all of blogs active posts. My problem comes where even though i explicitly search through the active_post ...
Hannah__'s user avatar
0 votes
1 answer
52 views

Rails : has_one and belongs_to same model

Say an admin can be the owner of an account and an account can have many admins. You would have association like the followings : class Account < ApplicationRecord belongs_to :account_owner, ...
David Geismar's user avatar
0 votes
1 answer
231 views

Rails has_one association through mapping table

Given these 4 Rails models: class Apple < ActiveRecord::Base has_one: ? end class Banana < ActiveRecord::Base has_one: ? end class FruitMapping < ActiveRecord::Base belongs_to :fruit, ...
Ron Avraham's user avatar
0 votes
0 answers
2k views

ReferenceError: Cannot access 'Model ' before initialization

I am facing an issue in defining the relationship between models in the Nodejs express app. I have two models one is Contact and the other is Conversation, I want to define a one-to-one relationship ...
Mrinal Verma's user avatar

15 30 50 per page
1
2 3 4 5
26