-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for One-to-One relations #133
Comments
For the Edit and New actions, the jQuery plugin you mention sounds great, even if I'd prefer vanilla js. The advantage of this plugin is that it allows the same usage for *ToMany relations, which would be incredibly awesome to handle easily these relations in EasyAdmin. Using the Form component is great too, because it allows the persistence of a brand new object, which I'm gonna need soon for a project in which there'll be entities that only are in the middle of a "ManyToMany with attribute" relation. Combining the two options does not seem to be a bad idea though it's gonna be harder to implement. Why don't allow the developer to set up this parameter in the entity configuration ? This would allow to use both systems, with a simple "if" statement in the controller. What do you think ? |
I think you're talking about embedded forms, right ? This was discussed in #109 and the approach @javiereguiluz suggested in the configuration seems good to me. @javiereguiluz : I don't know the selectize plugin, but I'm more used to the very good select2 or even chosen ones which provide way more examples. But as I never used selectize, I cannot talk about the The Show action seems good enough for the purposes. |
@ogizanagi Yep I'm talking about embedded forms. I think that the property config should be prototyped as said in #109 by @javiereguiluz , I mean this: SocialNetWork:
class: AppBundle\Entity\SocialNetwork
form:
fields: ['name', 'link', { property: 'logo', embedded: true }] but by changing the I propose the use of 4 choices:
I hope to have been the most objective and open-minded I could about this subject :) To conclude, this would allow us to directly set up the "relation render" in EasyAdmin by changing a potential Example: Website:
class: AppBundle\Entity\Website
form:
fields: ['name', 'host', { property: 'headerLogo', render: 'form' }]
Pages:
class: AppBundle\Entity\Page
form:
fields: ['name', 'content', 'slug', { property: 'category', render: 'inputs' } ]
Categories:
class: AppBundle\Entity\Category
form:
fields: ['name', 'slug', { property: 'parent', render: 'list' } ]
'Blog articles':
class: AppBundle\Entity\Post
form:
fields: ['name', 'content', 'slug', { property: 'medias', render: 'selectize' } ] What do you think ? |
Indeed, quite a good idea. E.g:
This will require to perform a request in order to get the amount of items in the database, but I don't think it will be a real issue. Do you think this is relevant ? |
I do, and that's precisely the behavior I imagined for setting a You're talking about the amout of items in the database, but in fact, we almost always need to retrieve the whole collection in the database. Pagination does not seem to be a good option in that case, so we need all of them. And with a simple The only exception is when using a selectize-like plugin, because we do not officially need to retrieve the collection, as it has to be handled by an API. A good option is to handle it only once, and fetch the objects in a javascript object. This allows faster usage in the autocompletion. |
I was not talking about pagination at all ^^. But using selectize (or select2 as I know it better) we can use AJAX requests to cleverly load entities within a search. (see "Loading remote data"). But this might not be suitable for our needs, as we will need to set one or more properties to search against in the configuration. So it cannot easily be guessed. If loading the whole collection, using Or...we can in fact use pagination (but I was not talking about that before ! 😸). We can load first a reasonable amount of the latest entities. Then, if the user doesn't find the one he needs from the list, click on a "load more" button (through AJAX). |
In fact, I was talking about pagination as a matter of demonstration that we need the whole collection, which can be a simple array ^^. You're totally right about very large databases, but there are not many solutions. Maybe we could check at first how many elements there is in the database, in order to pick a strategy ? But that sounds very heavy... By the way, for me the best possibility is to retrieve all elements in a JS object with a simple key=>value pair corresponding to primaryKey=>__toString() result. And for this, we must properly create a webservice. And this webservice cannot be optimized, because we cannot tell Doctrine to retrieve only "some" fields, as the __toString() method can use any field... Brainsplosion |
😅
Exactly. A
Exactly for the format. It will allow user to search for an entity against the
No. I don't understand the need to create a webservice called only once & used only for this purpose if we can just pass data to the form view.
Yep... that's why retrieving the whole collection should be limited according to the real amount of entities in the database, and IMO the best strategy for a selectize or another plugin will be to use pagination to load more on demand (then a webservice will be useful). |
So there's only two choices left for the selectize-like plugin:
What do you think ? |
three
|
Hmm, indeed, this is another good option :) |
Even it's another JS Plugin then selectize, i want to bring datatables into the game for this kind of lazy loading. Source: http://www.datatables.net/ It can preload some amount of data and you're able to load other things by ajax calls. I know it would be a load of work to do, but server-side processing + lazy loading could be worth the time. |
Have a config value with a limit on how many entries to show, if not set show all entries. |
Maybe we could take profit of the But that said, I think we should implement selectizer-like plugin as default, and implement all others solutions as possible ones for each entity. As usual, it should be "globalable", but the entity has priority. My conclusion is still the same as in this comment, and we can develop all solutions, it just needs some time, and a proper "let's go" from you @javiereguiluz for each solution 😃 Can we conclude a decision on this, even if we don't work on the development yet? |
(This issue is part of this meta issue which will add full support for all kinds of Doctrine relations)
The current situation
Support for one-to-one relations is half-finished:
List action
If the related entity is managed by EasyAdmin, the
list
action displays it as a link to theshow
action of that related Entity. Otherwise, it's displayed just as a regular text. This feature requires that the related entity defines the__toString()
method.Show action
Identical to
list
action: the related Entity is linked or not depending upon it's managed by EasyAdmin or not.Edit action
The related entity is transformed into a
<select>
list:When there are up to hundreds of items, the
<select>
displays them all:When there are thousands, the
<select>
just displays some of them (the most recently inserted items).New action
Same as the
edit
action:What I want to do
My questions to the community
If you like EasyAdminBundle and want to help improve it, please help me discussing this issue before starting to develop its code. Specifically, I'd like to ask the following questions:
<select>
? If not, do you have any clue about how to do that with Doctrine + Form component + selectize.js plugin?Thank you all for your help.
The text was updated successfully, but these errors were encountered: