Giter Club home page Giter Club logo

Comments (17)

MercerAsian avatar MercerAsian commented on July 28, 2024

Is there any answer/update to this? I haven't been able to find a solution.

from testdummy.

quickliketurtle avatar quickliketurtle commented on July 28, 2024

What's an example of what you are trying to do?
Using the Post example, something like Posts and Tags?

I was playing around with this, What syntax would you want to see?
I'm thinking something like this:

Post:
  title: Hello World $string
  body: $text
  published_at: $date
  author_id:
    type: Author
  pivot:
    type: Tag

from testdummy.

ssfinney avatar ssfinney commented on July 28, 2024

Yes, that's exactly what I want to do. Posts and Tags is a great example. For another example, think of Users and Roles.

I love the syntax!

πŸ‘

from testdummy.

aaronbullard avatar aaronbullard commented on July 28, 2024

Was curious if this is something under development? Or is there another solution that I'm missing?

from testdummy.

MercerAsian avatar MercerAsian commented on July 28, 2024

@aaronbullard You can still just create both models and then use Eloquent's attach() method.

from testdummy.

beedge72 avatar beedge72 commented on July 28, 2024

This seems like a fairly neccessary feature. Is there any update?

from testdummy.

quickliketurtle avatar quickliketurtle commented on July 28, 2024

Hi All, I started working on this last night. See https://github.com/quickliketurtle/TestDummy/tree/pivot

It's functional with Factory::create().

With build() it doesn't look like relationships were utilized so this change will not effect the build() method.

I still need to add some tests for this, need some more time to figure out the best way to test it.

Still a work in progress, but suggestions / feedback are welcome.

from testdummy.

quickliketurtle avatar quickliketurtle commented on July 28, 2024

UPDATE: Looks like the comment i replied to was deleted. Anyway i'll need to account for full namespace in fixtures.yaml file.


May be just the pasted code but the spacing on the pivot property look off.
i was seeing that error before writing the code to look for the pivot key
word.

However i did not test with namespaces so the type: \Role will error since
it is using that to build the save method. I'll add some code to account
for that.

In your example does the Role model site at the root of the namespace? or
is it in the Excel\Users namespace?

On Sun, Sep 28, 2014 at 2:54 AM, Kevin Bradshaw [email protected]
wrote:

@quickliketurtle https://github.com/quickliketurtle I have the
following relationship
Many Users have Many Roles
which Ive represented as follows:

Excel\Users\User:
username: $string$integer
email: $string$[email protected]
password: $string
timezone: $string
broker_id: $integer
created_at: $date
updated_at: $date
pivot:
type: \Role

\Role:
name: $string
created_at: $date
updated_at: $date

does that look correct? When I run my functional test based on this
relationship I get an error:

Couldn't sign in as member :
ErrorException: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

β€”
Reply to this email directly or view it on GitHub
#17 (comment).

from testdummy.

beedge72 avatar beedge72 commented on July 28, 2024

@quickliketurtle Yeah, Sorry I deleted my post when I realised the reason for the error I was receiving was not related to your branch (I was still accidentally using Master branch)
Im pretty sure the spacing on my .yml file is ok though (just tabbed the type value underneath pivot). but I agree, any solution would need to accommodate namespacing to keep it consistent with how it currently works

from testdummy.

quickliketurtle avatar quickliketurtle commented on July 28, 2024

Made a modification to account for namespaces with the pivot type. @beedge72 Let me know if this works with your current example.
Still need some tests...

from testdummy.

yecine06 avatar yecine06 commented on July 28, 2024

with the relase of the version 2 is there a new way to handle pivots ?

from testdummy.

abstractFlo avatar abstractFlo commented on July 28, 2024

@yecine06

+1 for that question

from testdummy.

yecine06 avatar yecine06 commented on July 28, 2024

@JeffreyWay how to do suggest handling this ?

from testdummy.

andrewmclagan avatar andrewmclagan commented on July 28, 2024

Not possible to create a pivot factory? Factory::create('PivotTable')

from testdummy.

yecine06 avatar yecine06 commented on July 28, 2024

@jeffreywy You closed thΓ© issue but You did'nt answer it

How should we handle this

from testdummy.

andrewmclagan avatar andrewmclagan commented on July 28, 2024

I have not tried it... but like I suggested:

Many-to-many relationships are simply defined by an intermediate table, called a pivot table.

This table can pretty much be accessed like any regular model can be in Laravel. So I'm assuming you can do something like Factory::create('PivotTable')

Just do a little bit of investigating from this point. Im sure its possible.

from testdummy.

philipmclifton avatar philipmclifton commented on July 28, 2024

I came up with a good solution to this but I had to modify TestDummy.

I added the ability to provide a second closure to a factory, this closure is run after a model is created and the model is passed into it.

$factory('App\Models\Application', 'base_app', function ($faker) {
    return [
        'id'        => 1,
        'name'      => 'name',
        'slug'      => 'slug',
        'website'   => $faker->url,
        'author_id' => 'factory:App\Models\User'
    ];
}, function($application){
    \Laracasts\TestDummy\Factory::create('App\Models\ApplicationUser', [
        'author_id'        => $application->author_id,
        'application_id' => $application->getKey(),
    ]);
});

In the example you can see that once its built the application and the user (author) it then runs the ApplicationUser model and creates the pivot between the tables.

This solves the pivot issue and many others.

https://github.com/philipmclifton/TestDummy

from testdummy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.