codeigniter-base-model icon indicating copy to clipboard operation
codeigniter-base-model copied to clipboard

One to one relationship?

Open paulcanning opened this issue 10 years ago • 3 comments

The documentation explains how to set up a one-to-many relationship, but who would I do a one to one relationship, when one table is involved in a one-to-many relationship with other tables?

E.g.

Table A --- Table B (one-to-one) Table A -< Table C (one-to-many) (this is set up using $belongs_to="table c" and $has_many="table a")

paulcanning avatar Mar 25 '14 16:03 paulcanning

When it gets much more complicated than a basic relationship, I'd start writing custom methods and using JOINs. The relationship functionality here is really only for quick rough-and-ready jobs.

On 25 March 2014 16:47, paulcanning [email protected] wrote:

The documentation explains how to set up a one-to-many relationship, but who would I do a one to one relationship, when one table is involved in a one-to-many relationship with other tables?

E.g.

Table A --- Table B (one-to-one) Table A -< Table C (one-to-many) (this is set up using $belongs_to="table c" and $has_many="table a")

Reply to this email directly or view it on GitHubhttps://github.com/jamierumbelow/codeigniter-base-model/issues/162 .

Jamie Rumbelow [email protected]

jamierumbelow avatar Mar 25 '14 18:03 jamierumbelow

Hmmm, do you think you would be able to add in some extra relationship stuff for a future release?

paulcanning avatar Mar 26 '14 10:03 paulcanning

Nope, sorry - like I said, the relationship stuff really isn't optimised or clever at all, and neither should it be! Write the JOINs yourself, or, use an ORM (Laravel's Eloquent is rather nice, and can be used outside of Laravel).

On 26 March 2014 10:44, paulcanning [email protected] wrote:

Hmmm, do you think you would be able to add in some extra relationship stuff for a future release?

Reply to this email directly or view it on GitHubhttps://github.com/jamierumbelow/codeigniter-base-model/issues/162#issuecomment-38669555 .

Jamie Rumbelow [email protected]

jamierumbelow avatar Mar 26 '14 10:03 jamierumbelow