laravel-ardent / ardent

Self-validating, secure and smart models for Laravel's Eloquent ORM
BSD 3-Clause "New" or "Revised" License
1.39k stars 211 forks source link

With pivot #92

Open ronlobo opened 11 years ago

ronlobo commented 11 years ago

Hi,

can somebody explain how https://github.com/laravelbook/ardent#cleaner-definition-of-relationships--since-20 works with pivot?

e.g. eloquent model relation function:

public function attributes () {
        return $this->belongsToMany('Attribute', collectionAttribute_collection', 'id_collection', 'id_collectionAttribute')->withPivot('value');
    }

now with ardent:

class Collection extends \LaravelBook\Ardent\Ardent {
  public static $relationsData = array(
    'attributes'  => array('belongsToMany', 'Attribute', 'table' => 'collections_have_attributes')
  );
}

where do I add the withPivot('value')?

Thanks in advance!

dbarn commented 11 years ago

Hi, I am interested in this too. Would hate to have to go back to the original relationships.

igorsantos07 commented 10 years ago

Sorry for the freaking long delay, men! Short answer: I have no clue. Long answer: I'll investigate what this method does and see how I could integrate it in the relationship array!

dalabarge commented 10 years ago

This was added by myself 2 months ago and has lived in documentation ever since. Simply add the named key pivotKeys to your relationship:

public static $relationsData = array(
    'attributes'  => array(
        'belongsToMany',
        'Attribute',
        'table' => 'collections_have_attributes',
        'pivotKeys' => array('foo', 'bar')
    )
);

@igorsantos07 it's safe to close this issue.

lvian commented 9 years ago

Hello @dalabarge and @igorsantos07 , sorry to post in this old topic, but I felt it was better then openning a new one.

I'm having some issues with the use of pivot relations in Ardent.

My pivot relation using Elloquent works fine, but when I try using the Ardent relations I keep getting "Undefined Columns" errors.

I created my relation as follow

public static $relationsData = array(
    'pessoas'  => array(
        'belongsToMany',
        'Pessoa',
        'table' => 'indicadorpessoa',
        'pivoteKeys' => array('ref_pessoa', 'ref_indicador')
    )
);

But when I try to get the relations I keep getting the following error

SQLSTATE[42703]: Undefined column: 7 ERRO: coluna indicadorpessoa.pessoa_id não existe LINE 1: ...r join "indicadorpessoa" on "pessoa"."pessoaid" = "indicador... ^ (SQL: select *, "indicadorpessoa"."indicador_id" as "pivot_indicador_id", "indicadorpessoa"."pessoa_id" as "pivot_pessoa_id", "indicadorpessoa"."ref_pessoa" as "pivot_ref_pessoa", "indicadorpessoa"."ref_indicador" as "pivot_ref_indicador" from "pessoa" inner join "indicadorpessoa" on "pessoa"."pessoaid" = "indicadorpessoa"."pessoa_id" where "indicadorpessoa"."indicador_id" = 6)

Ardent is trying to use the default keys 'pessoa_id' and 'indicador_id' along with the ones I'm passing ('ref_pessoa' and 'ref_indicador').

Any insight? Am I doing something wrong? The exacly same relation works fine with elloquent, I'll keep using it until I can figure whats wrong.

Sorry about grammar mistakes.

dalabarge commented 9 years ago

@lvian I'm no longer maintaining this commit nor Ardent in general as I've transitioned away from using it. Instead I would recommend esensi/model if your project supports PHP 5.4. It has support for this sort of relationship setup as a trait and also with validation among other things.

igorsantos07 commented 9 years ago

Hello @lvian. Unfortunately I have little to no knowledge of Laravel so I'm unable to help you on this matter :( But later this month I'll be looking for new maintainers to help us on this :)

And it's very good to know from this channel that the original developer have permanently abandoned the project in place of another one and never ever left feedback on why or suggestions of moving out as well. Didn't even bother on changing the repository ownership. That's what I call caring for your equals lol On 8 Oct 2014 19:19, "Daniel LaBarge" notifications@github.com wrote:

@lvian https://github.com/lvian I'm no longer maintaining this commit nor Ardent in general as I've transitioned away from using it. Instead I would recommend esensi/model https://github.com/esensi/model if your project supports PHP 5.4. It has support for this sort of relationship setup as a trait and also with validation among other things.

— Reply to this email directly or view it on GitHub https://github.com/laravelbook/ardent/issues/92#issuecomment-58437315.

dalabarge commented 9 years ago

@igorsantos07 was that last paragraph directed at me? I sure hope not. I'm neither the original developer nor ever was a maintainer – I tried to contribute but PRs remain unmerged and issues remain outstanding. I don't blame the maintainers for that so let's not send out the vibe that contributors who likewise owe this package nor it's user base anything are to blame. No one needs more drama.

I do hope that you find new maintainers later this month and will do my best to point your way anyone I can who is looking for an OS project to help with. Good luck and happy coding! :)

igorsantos07 commented 9 years ago

Thanks for your kindness. This is the second time I mis-guess GitHub usernames through email. I'll stop replying issues though my inbox. Sorry for that mistake :( (Obviously I mistook you for the original repository's owner)

Cheers! On 9 Oct 2014 11:04, "Daniel LaBarge" notifications@github.com wrote:

@igorsantos07 https://github.com/igorsantos07 was that last paragraph directed at me? I sure hope not. I'm neither the origin developer nor ever was a maintainer – I tried to contribute but PRs remain unmerged and issues remain outstanding. I don't blame the maintainers for that so let's not send out the vibe that contributors who likewise owe this package nor it's user base anything are to blame. No one needs more drama.

I do hope that you find new maintainers later this month and will do my best to point your way anyone I can who is looking for an OS project to help with. Good luck and happy coding! :)

— Reply to this email directly or view it on GitHub https://github.com/laravelbook/ardent/issues/92#issuecomment-58513864.

mihaiscurtucb commented 9 years ago

Hi @lvian, It might be extremely late and I apologize for necro-ing the issue, but if you change your code from pivoteKeys to pivotKeys it should work fine.

dalabarge commented 9 years ago

@mihaiscurtucb nice catch. I updated my snippet to reflect that for any other lost soul winding up on this issue. Sometimes the solutions are just starring us in the face! :+1: